NoSuchMethodError after including two libraries using ProGuard - android

I'm trying to include two libraries (panframe and indoo.rs) into my Android project using Gradle 2.1.2. Both were using ProGuard presumably to obfuscate their private methods. Since both libs use the same obfuscation pattern, a call to a static method from the indoo.rs worker service in onBind() leads to an ambiguity for the ClassLoader:
java.lang.NoSuchMethodError: No static method a(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/a/a/a/g; or its super classes (declaration of 'com.a.a.a.g' appears in /data/data/com.companytest/files/instant-run/dex/slice-panframe-1.9_e8c65b231b25083f170d9dc622b9f9f514e9ecef-classes.dex)
at com.a.a.h.a.j$a.(SourceFile:449)
at com.a.a.h.a.j.a(SourceFile:411)
at com.customlbs.service.Worker.onBind(SourceFile:184)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3834)
at android.app.ActivityThread.access$2200(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Apart from not obfuscating com.a.a.h.a.j.a in the indoo.rs library, is there any method to prevent this?

Related

app crashes on production but not in development - android app

My Project structure:
1- Kotlin app lib.
2-Java app calling methods from Kotlin lib.
From Java app I'm calling some methods from Kotlin lib. in development all works good and methods called successfully. after generating apk app starts with splash screen then crashes after getting location,
specifically when calling methods from Kotlin lib.
I think I missed something when generating apk with App and lib.
I tried this example and another about proguardFiles but no new result:
https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-creating-a-multi-project-build/
the error:
2020-05-28 13:22:29.970 339-339/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.app, PID: 339
java.lang.NoSuchMethodError: No static method asAttributeSet(Lh/a/a/a;)Landroid/util/AttributeSet; in class Landroid/util/Xml; or its super classes (declaration of 'android.util.Xml' appears in /system/framework/framework.jar:classes2.dex)
at c.a.n.g.inflate()
at ui.activity.MainActivity.onCreateOptionsMenu()
at android.app.Activity.onCreatePanelMenu(Activity.java:3183)
at androidx.fragment.app.d.onCreatePanelMenu()
at c.a.n.i.onCreatePanelMenu()
at androidx.appcompat.app.f$j.onCreatePanelMenu()
at c.a.n.i.onCreatePanelMenu()
at androidx.appcompat.app.i.o()
at androidx.appcompat.app.i$a.run()
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Appsflyer Crash : Fatal Exception: java.lang.NoSuchMethodError for MultipleInstallBroadcastReceiver.java line 43

I am getting a Crash which is reported in Crashlytics for com.appsflyer.MultipleInstallBroadcastReceiver.onReceive in MultipleInstallBroadcastReceiver.java class
This Crash is been reported for few users in all the android verisons
Fatal Exception: java.lang.NoSuchMethodError: No virtual method 藡(Landroid/content/Context;Landroid/content/Intent;)V in class Lcom/appsflyer/AppsFlyerLib; or its super classes (declaration of 'com.appsflyer.AppsFlyerLib' appears in /data/app/com.rapido.passenger-1/base.apk)
at com.appsflyer.MultipleInstallBroadcastReceiver.onReceive(MultipleInstallBroadcastReceiver.java:43)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3112)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1627)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
From the stack trace it seems to be an obfuscation issue (looking at the method name 藡)
What is the SDK version being used? Are there any proGuard (or other tool) rules configured for AppsFlyer?
If not I would suggest adding a -keep class com.appsflyer.** { *; } rule.
If you do not wish to share any additional information publicly, you can open a ticket with support#appsflyer.com, with the SDK version, any obfuscation related information and a link to this thread.

NoSuchFieldException when using SugarORM (big dependency)

When I call SugarRecord.listAll(SignInData.class) I get the following error:
java.lang.NoSuchFieldException: No field mFlags in class Landroid/service/media/MediaBrowserService$Result; (declaration of 'android.service.media.MediaBrowserService$Result' appears in /system/framework/framework.jar:classes2.dex)
at java.lang.Class.getDeclaredField(Native Method)
at android.support.v4.media.MediaBrowserServiceCompatApi24.<clinit>(MediaBrowserServiceCompatApi24.java:36)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at com.orm.util.ReflectionUtil.getDomainClass(ReflectionUtil.java:274)
at com.orm.util.ReflectionUtil.getDomainClasses(ReflectionUtil.java:258)
at com.orm.SchemaGenerator.createDatabase(SchemaGenerator.java:45)
at com.orm.SugarDb.onCreate(SugarDb.java:28)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.orm.SugarDb.getDB(SugarDb.java:38)
at com.orm.SugarRecord.getSugarDataBase(SugarRecord.java:35)
at com.orm.SugarRecord.find(SugarRecord.java:201)
at com.orm.SugarRecord.listAll(SugarRecord.java:127)
I use SugarORM in version 1.5 and have another dependency with many transitive dependencies. I already excluded some of them, so the gradle build & installation no longer complains about too many methods. But I needed to enable jumboMode, but no minifyEnabled.
I don't know if anything of this has to do with my error, but since it reffers to a dex-file, this is my only clue so far.
EDIT
I excluded even more transitive dependencies so I no longer need the jumboMode but it is still the same error.
In My case I got this Exception because there is no data table. and trying to retrieve data from table. Just insert some data first.(Sorry don't know the root cause of this Exception )

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat

I have updated the AppCompat libraries to 24.2.1 and the SDK to Android 7 in my Eclipse install.
Since that, I'm not capable to run any of my apps.
I appreciate if you can help a bit with that...
E/AndroidRuntime(17555): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat;
E/AndroidRuntime(17555): at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:196)
E/AndroidRuntime(17555): at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
E/AndroidRuntime(17555): at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
E/AndroidRuntime(17555): at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
E/AndroidRuntime(17555): at com.ryosoftware.calendareventsnotifier.MainActivity.onCreate(MainActivity.java:844)
E/AndroidRuntime(17555): at android.app.Activity.performCreate(Activity.java:5990)
E/AndroidRuntime(17555): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/AndroidRuntime(17555): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
E/AndroidRuntime(17555): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
E/AndroidRuntime(17555): at android.app.ActivityThread.access$900(ActivityThread.java:154)
E/AndroidRuntime(17555): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
E/AndroidRuntime(17555): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(17555): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(17555): at android.app.ActivityThread.main(ActivityThread.java:5294)
E/AndroidRuntime(17555): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17555): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(17555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/AndroidRuntime(17555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
E/AndroidRuntime(17555): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.os.BuildCompat" on path: DexPathList[[zip file "/data/app/com.ryosoftware.calendareventsnotifier-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(17555): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(17555): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(17555): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(17555): ... 18 more
E/AndroidRuntime(17555): Suppressed: java.lang.ClassNotFoundException: android.support.v4.os.BuildCompat
E/AndroidRuntime(17555): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(17555): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(17555): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(17555): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(17555): ... 19 more
E/AndroidRuntime(17555): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
You are getting NoClassDefFoundError & ClassNotFoundException
NoClassDefFoundError in Java comes when Java Virtual Machine is not
able to find a particular class at runtime which was available at
compile time.
FYI
You are using Eclipse. Android Studio is a far simpler way to develop for Android if you manage to get the hang of it. For developers who have been using Eclipse, migrating to Studio is a nightmare for them. Eclipse is dead (My personal opinion).
For your NoClassDefFoundError problem goto rebuild option under Project > Clean and then select the project you want to clean up .Then Restart your Eclipse and run again .
Solutions
Check your classpath contains that jar (AppCompat), if your classpath
doesn't contain the jar then just add that class in your classpath.
You should Use Android Studio instead of Eclipse . Read
Support Library Features
The Gradle build script dependency identifier for this library is as follows:
com.android.support:appcompat-v7:24.2.1
Then Clean-Rebuild-Restart IDE
In my case
clean project
invalidate and restart
it's work
Another ugly reason for this to be caused is if you're trying to attach a debugger with breakpoint on something that happens during Activity creation.
I added two classes in my java package and its working fine, keep both class as showing in below image:
AsyncTaskCompat.java
public class AsyncTaskCompat {
/**
* Executes the task with the specified parameters, allowing multiple tasks to run in parallel
* on a pool of threads managed by {#link android.os.AsyncTask}.
*
* #param task The {#link android.os.AsyncTask} to execute.
* #param params The parameters of the task.
* #return the instance of AsyncTask.
*/
public static <Params, Progress, Result> AsyncTask<Params, Progress, Result> executeParallel(
AsyncTask<Params, Progress, Result> task, Params... params) {
if (task == null) {
throw new IllegalArgumentException("task can not be null");
}
if (Build.VERSION.SDK_INT >= 11) {
// From API 11 onwards, we need to manually select the THREAD_POOL_EXECUTOR
AsyncTaskCompatHoneycomb.executeParallel(task, params);
} else {
// Before API 11, all tasks were run in parallel
task.execute(params);
}
return task;
}
}
AsyncTaskCompatHoneycomb.java
class AsyncTaskCompatHoneycomb {
static <Params, Progress, Result> void executeParallel(
AsyncTask<Params, Progress, Result> task, Params... params) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
}
In my case the error was caused due to the use of the entire gms:play-services library. Some components of gms:play-services refer to versions other than explicitly specified by you.
Use only the required play-services which are required e.g: 'com.google.android.gms:play-services-analytics:10.2.0' instead of 'com.google.android.gms:play-services:10.2.0'.
Also see: All com.android.support libraries must use the exact same version specification
Good read: https://blog.mindorks.com/avoiding-conflicts-in-android-gradle-dependencies-28e4200ca235
public class MApplication extends Application {
#Override
protected void attachBaseContext(Context paramContext) {
super.attachBaseContext(paramContext);
Helper.install(MApplication.this);
}
}
Here we override the attachBaseContext() method to add the Helper.install(MApplication.this); line of code.
Note: Since some of SDK classes now need to be loaded before using, the loading process is done by Helper.install(). Developer needs to invoke this method before using any SDK functionality. Failing to do so will result in unexpected crashes.
reference
Unless the app crashes with java.lang.NoClassDefFoundError: Failed resolution of:....
Update implementation com.google.android.gms:play-services-maps in gradle to a newer version.
That worked for me.
I had a very similar issue, the problem was using an old (deprecated) package, more that 4 years without maintenance. Check your reciently added packages and check if they're compatible with you Android SDK.
In my case, just cleaning and rebuilding the project worked for me.

Project is Using Dagger, but Library Project is using Guice. Can I use both?

So I have a project where I do dependency injection with Dagger, but I want to use a library project that uses RoboGuice.
When I try to run it, I get the following error when entering the library project:
java.lang.RuntimeException: Unable to start activity ComponentInfo{PROJECT.debug/LIBRARY.Activity}: com.google.inject.CreationException: Guice creation errors:
1) Could not find a suitable constructor in PROJECT.AdvertisingTrackingAggregator. Classes must have either one (and only one) constructor annotated with #Inject or a zero-argument constructor that is not private.
at PROJECT.AdvertisingTrackingAggregator.class(Unknown Source)
while locating PROJECT.AdvertisingTrackingAggregator
for field at PROJECT.ProjectApplication._advertistingTrackingAggregator(Unknown Source)
at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)
1 error
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
....
Caused by: com.google.inject.CreationException: Guice creation errors:
1) Could not find a suitable constructor in PROJECT.AdvertisingTrackingAggregator. Classes must have either one (and only one) constructor annotated with #Inject or a zero-argument constructor that is not private.
at PROJECT.AdvertisingTrackingAggregator.class(Unknown Source)
while locating PROJECT.AdvertisingTrackingAggregator
for field at PROJECT.ProjectApplication._advertistingTrackingAggregator(Unknown Source)
at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:83)
at roboguice.RoboGuice.setBaseApplicationInjector(RoboGuice.java:94)
at roboguice.RoboGuice.setBaseApplicationInjector(RoboGuice.java:139)
at roboguice.RoboGuice.getBaseApplicationInjector(RoboGuice.java:59)
at roboguice.RoboGuice.getInjector(RoboGuice.java:149)
at com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity.onCreate(RoboSherlockFragmentActivity.java:31)
at LIBRARY.ui.activity.AbstractLibraryActivity.onCreate(AbstractLibraryActivity.java:149)
at LIBRARY.ui.activity.LibraryLandingActivity.onCreate(LibraryLandingActivity.java:68)
at android.app.Activity.performCreate(Activity.java:5720)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
... 10 more
Does the Library need to configure itself with Module to avoid looking for #Inject annotations that I use in my project via Dagger?
How do I get past the Guice/Dagger fight?

Categories

Resources