greybax / cordova-plugin-proguard

:white_square_button: Cordova Plugin for ProGuard
MIT License
51 stars 265 forks source link

Crash on start app with latest version #10

Closed Hanzofm closed 4 years ago

Hanzofm commented 5 years ago

Hi, when I install this plugin on my app with last version of cordova Android (7.1.4) it crashes on start.

Previously with version 1.0 of the plugin and cordova android 6.4.4 it works correctly. Now with version 2.0 of the plugin and cordova Android 7.1.4 crashes at startup with this logcat:

 --------- beginning of crash
2018-12-14 09:52:43.125 21666-21666/es.gva.mobilendo.aire E/AndroidRuntime: FATAL EXCEPTION: main
    Process: es.gva.mobilendo.aire, PID: 21666
    java.lang.RuntimeException: Unable to start activity ComponentInfo{es.gva.mobilendo.aire/es.gva.mobilendo.aire.MainActivity}: java.lang.RuntimeException: Failed to create webview. 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
     Caused by: java.lang.RuntimeException: Failed to create webview. 
        at org.apache.cordova.CordovaWebViewImpl.createEngine(CordovaWebViewImpl.java:82)
        at org.apache.cordova.CordovaActivity.makeWebViewEngine(CordovaActivity.java:206)
        at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:202)
        at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:146)
        at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224)
        at es.gva.mobilendo.aire.MainActivity.onCreate(MainActivity.java:39)
        at android.app.Activity.performCreate(Activity.java:6955)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6776) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 
     Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, class org.apache.cordova.CordovaPreferences]
        at java.lang.Class.getConstructor0(Class.java:2204)
        at java.lang.Class.getConstructor(Class.java:1683)
        at org.apache.cordova.CordovaWebViewImpl.createEngine(CordovaWebViewImpl.java:79)
        at org.apache.cordova.CordovaActivity.makeWebViewEngine(CordovaActivity.java:206) 
        at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:202) 
        at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:146) 
        at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224) 
        at es.gva.mobilendo.aire.MainActivity.onCreate(MainActivity.java:39) 
        at android.app.Activity.performCreate(Activity.java:6955) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6776) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 
2018-12-14 09:52:43.127 4152-4775/? D/Debug: !@DumpState : SHIP
2018-12-14 09:52:43.127 4152-4775/? D/Debug: !@DumpState : debug level:0x4f4c
2018-12-14 09:52:43.127 4152-4775/? D/Debug: !@Dumpstate : Finally, system will skip dumpstate

    --------- beginning of system
2018-12-14 09:52:43.127 4152-4775/? W/ActivityManager:   Force finishing activity es.gva.mobilendo.aire/.MainActivity

This is my Cordova Plugin List:

cordova-fabric-plugin 1.1.14-dev "cordova-fabric-plugin"
cordova-plugin-advanced-http 2.0.1 "Advanced HTTP plugin"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-googlemaps 2.4.6 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.2.5 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-proguard 2.0.0 "Cordova plugin ProGuard"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-x-socialsharing 5.4.3 "SocialSharing"
cordova-sqlite-storage 2.5.2 "Cordova sqlite storage plugin"
es6-promise-plugin 4.2.2 "Promise"

This is my Ionic Info:

Ionic:

   ionic (Ionic CLI)  : 4.0.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.9

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.1.4, ios 4.5.5

System:

   Android SDK Tools : 26.1.1
   ios-deploy        : 1.9.2
   ios-sim           : 6.1.2
   NodeJS            : v9.9.0 (/usr/local/bin/node)
   npm               : 5.7.1
   OS                : macOS High Sierra
   Xcode             : Xcode 10.1 Build version 10B61

Environment:

   ANDROID_HOME : /Users/juanramos/Library/Android/sdk

What would be happening?

greybax commented 5 years ago

@SujitSingh did you faced with this issue while worked on https://github.com/greybax/cordova-plugin-proguard/pull/5?

SujitSingh commented 5 years ago

I didn't face any issue with Cordova 7 and above. I am still using forked repo in my project. Let me check with latest version of this plugin.

Hanzofm commented 5 years ago

@SujitSingh did you faced with this issue while worked on #5?

If this PR is included on version 2.0 of the plugin, my problem persist with latest version, my problem is with version 2.0.

greybax commented 5 years ago

@Hanzofm is v1 works fine with latest version of Cordova? If yes I can revert @SujitSingh PR ?

adhityan commented 5 years ago

Actually, I face the same issue when I use this.

Cordova version - 8.1.2 Android - 6.4.0 Exception -

E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{...}: java.lang.RuntimeException: Failed to create webview. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2841) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:6656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) Caused by: java.lang.RuntimeException: Failed to create webview. at org.apache.cordova.CordovaWebViewImpl.createEngine(CordovaWebViewImpl.java:83) at org.apache.cordova.CordovaActivity.makeWebViewEngine(CordovaActivity.java:206) at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:202) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:146) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224) at uat.bitnudge.rakbank.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:7074) at android.app.Activity.performCreate(Activity.java:7065) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2794) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:176)  at android.app.ActivityThread.main(ActivityThread.java:6656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)  Caused by: java.lang.NoSuchMethodException: [class android.content.Context, class org.apache.cordova.CordovaPreferences] at java.lang.Class.getConstructor0(Class.java:2320) at java.lang.Class.getConstructor(Class.java:1725) at org.apache.cordova.CordovaWebViewImpl.createEngine(CordovaWebViewImpl.java:80) at org.apache.cordova.CordovaActivity.makeWebViewEngine(CordovaActivity.java:206)  at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:202)  at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:146)  at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224)  at uat.bitnudge.rakbank.MainActivity.onCreate(MainActivity.java:39)  at android.app.Activity.performCreate(Activity.java:7074)  at android.app.Activity.performCreate(Activity.java:7065)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2794)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:176)  at android.app.ActivityThread.main(ActivityThread.java:6656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 

greybax commented 5 years ago

@adhityan did you try v1 of this plugin?

rodrigograca31 commented 5 years ago

I'm facing the same issue

adb logcat | grep -i webview

05-18 01:17:54.009  1705  1705 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hello/com.example.hello.MainActivity}: java.lang.RuntimeException: Failed to create webview. 
05-18 01:17:54.009  1705  1705 E AndroidRuntime: Caused by: java.lang.RuntimeException: Failed to create webview. 

The doesnt seem to be this plugin problem.... At least in my case I only need to add minifyEnabled true to my release configs in build.gradle and my app no longer works.

It seems that's the case with any Cordova app. If I add minifyEnabled true it starts using ProGuard and the app no longer works. We should create an issue in the cordova-android repos.....

greybax commented 5 years ago

@rodrigograca31 Did you try to set minifyEnabled true without this plugin? Would it work in this case?

rodrigograca31 commented 5 years ago

@greybax Yes, thats what I was saying, just setting minifyEnabled true makes any cordova app stop working.... its not even related to this plugin............

Hanzofm commented 5 years ago

Finally adding this to proguard-custom.txt solves my problem:

# These clases contain references to cordova webView
-keep class com.ionicframework.cordova.webview.** {*; }
-keep class com.ionicframework.cordova.webview.*

If uses this plugin with relative modern version of Ionic and WebView the above rules are necessary

Works with -Ionic 3.9.6 -Cordova CLI 8.0.0 -Cordova-Android 8.0.0 -Cordova webview plugin 2.2.5

greybax commented 5 years ago

@Hanzofm looks good for me. Could you send PR for this fix?

Hanzofm commented 5 years ago

Done

rodrigograca31 commented 5 years ago

@Hanzofm thanks for comming back with a solution! I'm also using ionic and "modern version of everything" and simply enabling minifyEnabled true was making my app crash.

whenever I got some time I will try your solution and see if it solves the problem! I bet it does! Thanks!

Hanzofm commented 5 years ago

@Hanzofm thanks for comming back with a solution! I'm also using ionic and "modern version of everything" and simply enabling minifyEnabled true was making my app crash.

whenever I got some time I will try your solution and see if it solves the problem! I bet it does! Thanks!

Where are you using the minifyEnabled true?

rodrigograca31 commented 5 years ago

@Hanzofm I tested it by manually adding it to my app build.gradle in platforms/android/ ...

I also tried the same with a brand new cordova only app and as soon as I added minifyEnabled true to build.gradle the app stopped working......... I will give it a try another day.....

greybax commented 5 years ago

bumped npm package to v2.0.1 with latest @Hanzofm changes

Yuripetusko commented 5 years ago

hmm I still get java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bridebook.mobileapp/com.bridebook.mobileapp.MainActivity}: java.lang.RuntimeException: Failed to create webview. ... Caused by: java.lang.ClassNotFoundException: com.ionicframework.cordova.webview.IonicWebViewEngine even with 2.0.1, I can see

# These clases contain references to cordova webView
-keep class com.ionicframework.cordova.webview.** {*; }
-keep class com.ionicframework.cordova.webview.*

In my proguard-custom.txt

greybax commented 5 years ago

did you clean up your package before? I've faced with this issue before, because I saw plugin v2.0.0 in my package

devtechvalens commented 5 years ago

I am also getting the same error-

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tv.gpd/com.tv.gpd.MainActivity}: java.lang.RuntimeException: Failed to create webview.

by using -

# These clases contain references to cordova webView
-keep class com.ionicframework.cordova.webview.** {*; }
-keep class com.ionicframework.cordova.webview.*

In my proguard-custom.txt

I am using webview plugin version - 2.3.2 Even I tested the same with webview version - 2.2.5

I am working with - -Ionic 3.19.0 -Cordova CLI 7.0.0 -Cordova-Android 8.0.0

Any help will be appreciated.

jd048 commented 4 years ago

I am facing same issue once added proguard to the app is now crashing.

greybax commented 4 years ago

Made a fix as it describes on SO https://stackoverflow.com/questions/37994892/cordova-android-5-1-1-apk-obfuscation-with-proguard-confusion/57273266#57273266:

added

-dontwarn com.google.android.gms.**
rodrigograca31 commented 4 years ago

:thinking: I need to give this plugin another try one of these days....

@greybax seems you have a Patreon, that's great! Maybe you should try to get approved for GitHub Sponsors and set it up for this project!?

greybax commented 4 years ago

@rodrigograca31 I have approved Github Sponsors, but not sure why its better than Patreon.

rodrigograca31 commented 4 years ago

Good question I just think its easier to stay inside github than go outside... but now that I think about it its Microsoft money..... :sob:

also: during the first year they match the donations that means double the money (free money from Microsoft :joy:)