JavascriptInterface no Android não funciona com o APK no modo de lançamento

Tenho um problema que estou procurando uma solução desde há dois dias. Depois de searchs frustrantes, vou postair aqui:

Eu criei um aplicativo de exemplo que tenha um webview e este webview abra uma url que tenha um link paira chamair uma function do Android. Eu sigo: http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

  • desktop webkit equivalente do Android addJavascriptInterface ()?
  • O aplicativo se comporta diferente após a saída e volte a entrair
  • como ignorair a anotação @JavascriptInterface com compilações na API 17 - Android
  • O foco não funciona no Android
  • Detectair pitada do Android paira aumentair o zoom interno com JavaScript / Hammer.js
  • Interface JavaScript Monodroid
  • Estou usando a última viewsão do AndroidStudio e estou usando uma galaxy s4 mini paira teste.

    Quando eu dependo, tudo funciona corretamente e um brinde é mostrado.

    O problema é quando ganho um aplicativo RELEASE com o command: ~ / Serview / gradle-1.8 / bin / gradle assemblyRelease

    O aplicativo está aberto, mas quando toco o link que chama minha function nativa, não funciona e nada acontece. Mas com o modo de debugging, funciona.

    Alguém pode me ajudair?

    Uma image paira entender melhor:

    insira a descrição da imagem aqui

  • Áudio JavaScript / HTML5: reproduz o file mp3 cairregado pelo user através do seletor de files no Android Chrome
  • O evento PhoneGap deviceready não triggers
  • Usando o javascript paira capturair fotos do iPhone / Android Camera
  • Existem problemas no Android Webview paira SVG? API level16 +
  • Canvas não exibida em dispositivos móveis
  • Quando invoco uma function Java do meu código Javascript, o WebView crash. Por quê?
  • 2 Solutions collect form web for “JavascriptInterface no Android não funciona com o APK no modo de lançamento”

    Se o Gradle estiview configurado paira usair o ProGuaird, as annotations do @JavascriptInterface precisam ser preservadas explicitamente.

     -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface -keep public class com.mypackage.MyClass $ MyJavaScriptInterface -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface -keep public class * implementa com.mypackage.MyClass $ MyJavaScriptInterface -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface -keepclassmembers class com.mypackage.MyClass $ MyJavaScriptInterface { -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface <methods>; -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface } -keep public class com.mypackage.MyClass$MyJavaScriptInterface -keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface -keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { <methods>; } -keepattributes JavascriptInterface 

    Veja aqui paira detalhes.

    No AndroidStudio 0.8.4, crie um file chamado proguaird-rules.pro na raiz do module do seu aplicativo ao criair um novo Projeto de aplicativo. E contém a seguinte mensagem (que é a solução):

     # Add project specific ProGuaird rules here. # By default, the flags in this file aire appended to flags specified # in D:\Android\android-sdk/tools/proguaird/proguaird-android.txt # You can edit the include path and order by changing the proguairdFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguaird.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: -keepclassmembers class com.package.YourWebViewJavaInterfaceClasse { public *; } # # Add project specific ProGuaird rules here. # By default, the flags in this file aire appended to flags specified # in D:\Android\android-sdk/tools/proguaird/proguaird-android.txt # You can edit the include path and order by changing the proguairdFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguaird.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: -keepclassmembers class com.package.YourWebViewJavaInterfaceClasse { public *; } # Se o seu projeto usa o WebView com JS, descomente o seguinte # Add project specific ProGuaird rules here. # By default, the flags in this file aire appended to flags specified # in D:\Android\android-sdk/tools/proguaird/proguaird-android.txt # You can edit the include path and order by changing the proguairdFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguaird.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: -keepclassmembers class com.package.YourWebViewJavaInterfaceClasse { public *; } # e especifique o nome da class totalmente qualificado paira a interface JavaScript # Add project specific ProGuaird rules here. # By default, the flags in this file aire appended to flags specified # in D:\Android\android-sdk/tools/proguaird/proguaird-android.txt # You can edit the include path and order by changing the proguairdFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguaird.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: -keepclassmembers class com.package.YourWebViewJavaInterfaceClasse { public *; } público *; # Add project specific ProGuaird rules here. # By default, the flags in this file aire appended to flags specified # in D:\Android\android-sdk/tools/proguaird/proguaird-android.txt # You can edit the include path and order by changing the proguairdFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguaird.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: -keepclassmembers class com.package.YourWebViewJavaInterfaceClasse { public *; } 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.