问题
I'm using gcm and the app failed to start due to this error:
AndroidRuntime: java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.()' is inaccessible to class 'com.google.android.gms.iid.zzd' (declaration of 'com.google.android.gms.iid.zzd' appears in /data/app/net.segoia.opengroups.mobile-1/base.apk:classes2.dex)
This was caused by this line:
InstanceID instanceID = InstanceID.getInstance(this);
The problem is that when building for api level 27, support for android v4 is dropped.
回答1:
What solved the problem is adding these two build hints:
android.supportV4=true
android.supportv4Dep=compile 'com.android.support:support-v4:23.+'
This took a while to figure out, especially because the android.supportV4Dep is not even documented, and the android.supportV4 alone is not enough. I have learned about the android.supportV4Dep from another stackoverflow answer to a different question, so I thought I would document this here.
来源:https://stackoverflow.com/questions/52181747/codenameone-android-app-fails-to-start-when-building-with-android-buildtoolsve