Phonegap 2.4 Android Proguard config
Asked Answered
P

2

7

I've upgraded a build from Phonegap (Cordova) 2.0 to 2.4 and everything was working fine in dev until I actually came to testing the final release apk. What I'm finding, after a lot of time wasted, is that for some reason now when I run the build my proguard config is breaking the phonegap build in some way that means that when it runs the deviceready is never called. There seem to be no errors when building, nor running and nothing as far as I can see but I'm guessing something is silently failing in the cordova js as i'm not getting compile / log errors on the device.

As I say this is ONLY when having ran the Proguard obfs in the build process. If i turn off Proguard it all works fine. I reverted all my code back to 2.0 to be sure and that is all fine so somewhere along the way there has been a stuble change that is seemingly not documented / or nobody has hit just yet (2.4 only came out a few weeks ago - at time of writing 26th feb 2013).

My Proguard config contains the following for phonegap (as well as some other standard config)

-keep public class * extends com.phonegap.api.Plugin
-keep public class * extends org.apache.cordova.api.Plugin
-keep public class org.apache.cordova.DroidGap
-keep public class org.apache.cordova.**
-keep public class org.apache.**
-dontwarn android.webkit.*
-dontwarn org.apache.**

and decompiling the dex doesn't seem to throw any light - everything looks ok at a glance...

Anyone have any ideas???

Pentobarbital answered 26/2, 2013 at 11:6 Comment(3)
random not related(?) question: why are you using DroidGap and not CordovaWebView?Bananas
This could be an avenue to investigate @Edward ... My app is extending DriodGap - as it's been around since before 2.0 (i think). The proguard config -keep public org.apache.cordova i've got from trauling other posts about issues with proguard and phonegap. The app fires up fine and loads correct urls but only seems to have a problem when loading the js.Pentobarbital
you can use cordova plugin proguard alfilatov.com/posts/…Agility
C
11

Try replacing the Cordova "keep" settings in your proguard-project.txt with the following line, which should maintain all Cordova classes, fields, and methods, both public and private (and thus reenable deviceready):

-keep class org.apache.cordova.** { *; }

Then you just need to include your class(es) (presumably extending CordovaPlugin, not just Plugin) e.g.

pre-v3:

-keep public class * extends org.apache.cordova.api.CordovaPlugin

v3+:

-keep public class * extends org.apache.cordova.CordovaPlugin
Creolized answered 11/3, 2013 at 16:7 Comment(1)
You are the champ! It did not occur to me till now.Unspoken
B
0

Phonegap Plugins are being excluded from the final APK I guess. Cordova.js probably doesn't even exist to give errors.

Bananas answered 26/2, 2013 at 11:34 Comment(1)
the js is included manually and it's hosted on the server... I'm about to start stepping through the JS code to work out exactly if / where it is failing. You may well be right that perhaps a plugin is missing / renamed when the obfuscate runs and the JS fails silently. I have it running through Weinre as well but again, not reporting any parse / runtime js errors.Pentobarbital

© 2022 - 2024 — McMap. All rights reserved.