I have a problem passing a custom class to another activity resulting in a Activity Manager crash. I have a class like this:
public class MyClass implements Serializable/Parcelable {
public final String a;
public final Long b;
public final Boolean c;
}
Intent intent = new Intent(getActivity(), TargetActivity.class);
Bundle parameter = new Bundle();
parameter.putParcelable(TargetActivity.DATA_KEY, instance_of_my_class);
startActivity(intent, parameter);
I have tried both Serializable as well as Parcelable and both ways fail with the same problem: ClassNotFoundException.
There are some older discussions about this where setClassLoader and setExtrasClassLoader are recommended, unfortunately it does not work. For example I have tried parameter.setClassLoader(getClass().getClassLoader()); the result was the same.
Anyone knows the solution? Is it possible that a third party library has an influence on this? (I have EventBus in the project)
The stack trace in the Parcelable case looks like this:
08-23 14:40:37.086 1487-1783/system_process E/Parcel: Class not found when unmarshalling: com.example.MyClass
java.lang.ClassNotFoundException: com.example.MyClass
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getString(BaseBundle.java:918)
at android.app.ActivityOptions.<init>(ActivityOptions.java:570)
at com.android.server.am.ActivityRecord.<init>(ActivityRecord.java:417)
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1482)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:951)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3369)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3356)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:139)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2208)
at android.os.Binder.execTransact(Binder.java:446)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.MyClass" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getString(BaseBundle.java:918)
at android.app.ActivityOptions.<init>(ActivityOptions.java:570)
at com.android.server.am.ActivityRecord.<init>(ActivityRecord.java:417)
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1482)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:951)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3369)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3356)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:139)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2208)
at android.os.Binder.execTransact(Binder.java:446)
Suppressed: java.lang.ClassNotFoundException: com.example.MyClass
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Classes implementing the Parcelable interface must also have a non-null static field called CREATOR of a type that implements the Parcelable.Creator interface.
Ref: https://developer.android.com/reference/android/os/Parcelable.html
To make that in a easy way try to find plugins which will handle parcelable creation.
Example:
https://github.com/mcharmas/android-parcelable-intellij-plugin
Related
Well, i just added some gplay service dependencies and then i remove the dependency
then this just got pop up
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.yukngaji.transaksi.sandbox, PID: 31258
java.lang.RuntimeException: Unable to instantiate application com.app.yukngaji.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.app.yukngaji.MyApplication" on path: DexPathList[[zip file "/data/app/com.app.yukngaji.transaksi.sandbox-mHCwz7RvI-rgiO3KfiNFtQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.yukngaji.transaksi.sandbox-mHCwz7RvI-rgiO3KfiNFtQ==/lib/arm64, /system/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1123)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6251)
at android.app.ActivityThread.access$1300(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7179)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app.yukngaji.MyApplication" on path: DexPathList[[zip file "/data/app/com.app.yukngaji.transaksi.sandbox-mHCwz7RvI-rgiO3KfiNFtQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.yukngaji.transaksi.sandbox-mHCwz7RvI-rgiO3KfiNFtQ==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:47)
at android.app.Instrumentation.newApplication(Instrumentation.java:1120)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1115)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6251)
at android.app.ActivityThread.access$1300(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7179)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
i already added MultiDex Enable, androidx.multidex.blablabla, and try all thing on the internet, but it won't work
In your Application subclass override the attachBaseContext method and do this:
First you need to create a subclass of Application Class like this:
JAVA:
public class MyApplication extends Application{
//override this method
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this)
}
}
Kotlin:
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
This should work
I am currently developing an alarm library, that needs to store multiple alarm details in sqlite database.
So I used google's Room persistence library, with my alarm library.
I have added below code to build.gradle.
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
I have added database class
#Database(entities = AlarmDetails.class, version = 1)
public abstract class AlarmDatabase extends RoomDatabase {
public abstract AlarmDao alarmDao();
}
I have also added Data Access Object
#Dao
public interface AlarmDao {
#Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(AlarmDetails alarmDetails);
#Update
void update(AlarmDetails alarmDetails);
#Delete
void delete(AlarmDetails alarmDetails);
#Query("SELECT * FROM alarms")
List<AlarmDetails> getAll();
}
I am creating a database instance in the main class of my library as below
/*Constructor*/
public AlarmBase(Context mcontext,Context ncontext) {
this.mContext = mcontext;
alarmDatabase= Room.databaseBuilder(ncontext,
AlarmDatabase.class, "alarm_db")
.build();
}
i am calling the above constructor from my demo project and passing application context as below
Context applicationContext=MyApplicationClass.getContext();
alarmBase = new AlarmBase(this,applicationContext);
And this is my application class
public class MyApplicationClass extends MultiDexApplication {
private static MultiDexApplication instance;
#Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getContext() {
return instance.getApplicationContext();
}
}
But when I run the project I get the below error
--------- beginning of crash
02-21 20:23:34.643 11930-11930/com.mid.alarmdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mid.alarmdemo, PID: 11930
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mid/alarmlib/roomsqlite/AlarmDatabase;
at com.mid.alarmlib.AlarmBase.<init>(AlarmBase.java:39)
at com.mid.alarmdemo.MainActivity.onCreate(MainActivity.java:54)
at android.app.Activity.performCreate(Activity.java:6362)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548)
at android.app.ActivityThread.access$1100(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5613)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mid.alarmlib.roomsqlite.AlarmDatabase" on path: DexPathList[[zip file "/data/app/com.mid.alarmdemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mid.alarmdemo-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.mid.alarmlib.AlarmBase.<init>(AlarmBase.java:39)
at com.mid.alarmdemo.MainActivity.onCreate(MainActivity.java:54)
at android.app.Activity.performCreate(Activity.java:6362)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548)
at android.app.ActivityThread.access$1100(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5613)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Suppressed: java.lang.NoClassDefFoundError: com.mid.alarmlib.roomsqlite.AlarmDatabase
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:338)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.mid.alarmlib.roomsqlite.AlarmDatabase
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I was able to run the project along with my library until I added Room persistence to my library
I just added below lines to the build.gradle(Module app) of the project also,
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
and it worked fine
In the Navigation Library version alpha09+ (using alpha11) I am experiencing a ClassNotFoundException for one of my data classes which I defined as an argType in my navigation graph.
app:argType="com.package.app.data.model.user.User.Full"
This class does exist. When downgrading back to alpha08, the issue does not appear to happen.
This is the full stacktrace:
2019-01-28 10:30:32.028 6970-6970/com.package.app.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.app.debug, PID: 6970
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.app.debug/com.package.app.ui.MainActivity}: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class fragment
Caused by: java.lang.RuntimeException: Exception inflating com.package.app.debug:navigation/navigation_main line 376
at androidx.navigation.NavInflater.inflate(NavInflater.java:89)
at androidx.navigation.NavController.setGraph(NavController.java:424)
at androidx.navigation.NavController.setGraph(NavController.java:406)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:226)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1684)
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManager.java:1930)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3745)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
at co.lokalise.android.sdk.core.LokaliseLayoutInflater$PrivateWrapperFactory2.onCreateView(LokaliseLayoutInflater.java:362)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at co.lokalise.android.sdk.core.LokaliseLayoutInflater.inflate(LokaliseLayoutInflater.java:84)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.package.app.ui.MainActivity.onCreate(MainActivity.kt:75)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
2019-01-28 10:30:32.031 6970-6970/com.package.app.debug E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.package.app.data.model.user.User.Full
at androidx.navigation.NavType.fromArgType(NavType.java:180)
at androidx.navigation.NavInflater.inflateArgument(NavInflater.java:181)
at androidx.navigation.NavInflater.inflateArgumentForDestination(NavInflater.java:145)
at androidx.navigation.NavInflater.inflate(NavInflater.java:120)
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavInflater.inflate(NavInflater.java:80)
... 41 more
Caused by: java.lang.ClassNotFoundException: com.package.app.data.model.user.User.Full
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at java.lang.Class.forName(Class.java:378)
at androidx.navigation.NavType.fromArgType(NavType.java:168)
... 46 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.app.data.model.user.User.Full" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/base.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_resources_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 50 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
2019-01-28 10:30:32.031 6970-6970/com.package.app.debug E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
... 6 more
I have updated the Navigation Library component from alpha08 to alpha11. When they released alpha09, I also updated and had this same issue and thought it was a bug, so I waited. Now, the issue still persists and I can't seem to be able to figure out want went wrong.
I have already disabled ProGuard for debugging, as well as minify and have enabled Multidex to see if this would help.
debug {
minifyEnabled false
useProguard false
versionNameSuffix '-DEBUG'
applicationIdSuffix '.debug'
}
The class has also been added to the proguard-rules, to see if that would work.
-keep class com.package.app.data.model.** { *; }
As far as I'm concerned, this should work? Android Studio also generates the XML for me exactly like this.
Thanks in advance.
After all, it was a known bug in Android Studio.
Since the release of 1.0.0-alpha09, something changed in the way they handled inner classes.
If a parcelable is an inner class, it has to be written like:
com.domain.app.User$Full where Full is the parcelized object.
If you want to read more about this, check out this answer on Google's Issue Tracker: https://issuetracker.google.com/u/2/issues/123614632#comment4
Just faced problem similar to this issue and I got realized I didn't set up any proguard rules. Here's additional information that might be helpful.
The following codes are found in navigation component version 2.2.0-rc02.
// NavType.java
try {
String className;
if (type.startsWith(".") && packageName != null) {
className = packageName + type;
} else {
className = type;
}
if (type.endsWith("[]")) {
className = className.substring(0, className.length() - 2);
Class<?> clazz = Class.forName(className);
if (Parcelable.class.isAssignableFrom(clazz)) {
return new ParcelableArrayType(clazz);
} else if (Serializable.class.isAssignableFrom(clazz)) {
return new SerializableArrayType(clazz);
}
} else {
Class<?> clazz = Class.forName(className);
if (Parcelable.class.isAssignableFrom(clazz)) {
return new ParcelableType(clazz);
} else if (Enum.class.isAssignableFrom(clazz)) {
return new EnumType(clazz);
} else if (Serializable.class.isAssignableFrom(clazz)) {
return new SerializableType(clazz);
}
}
throw new IllegalArgumentException(className + " is not Serializable or "
+ "Parcelable.");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
You can see it looks for classes using Class.forName(String) method. So keeping their names is enough.
# Instead of -keep
-keepnames class com.package.app.data.model.** { *; }
And if packageName is provided, you can omit package name from value of argType attribute, but sadly it won't work if you use some application id suffixes depending on build variants. (So do not omit package name from argType)
I had the same problem, my argType was the class that was the Subclass of the fragment. I moved that class out of the fragment and problem was fixed
Today, I was making an application with the newest Android 7.1 feature, App Shortcuts. At first, it runs well on Android 7.1.1. However, when I made it run on MIUI 8 on Android M, it broke unfortunately. I have wrote something to make it run on M or lower version, but it broke again. I was confused. I hope someone can give me a solution on this problem. I will be appreciated if someone can help me. Thanks anyway!
Here is my code.
findViewById(R.id.textView5).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addshortcut();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
shortcutManager = getSystemService(ShortcutManager.class);
}
public void addshortcut(){
TextView textView = (TextView)findViewById(R.id.textView5);
String name = textView.getText().toString();
ShortcutInfo dynamicShortcut = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
dynamicShortcut = new ShortcutInfo.Builder(this, "shortcut_dynamic-zty")
.setShortLabel(name)
.setLongLabel(name)
.setIcon(Icon.createWithResource(this,R.drawable.ic_account_circle))
.setIntents(
new Intent[]{
new Intent(Intent.ACTION_VIEW, Uri.EMPTY,com.zengtianyu.gallery1.DetailZTY.this, DetailZTY.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
})
.build();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
shortcutManager.setDynamicShortcuts(Arrays.asList(dynamicShortcut));
}
Toast.makeText(this,"添加成功",Toast.LENGTH_SHORT).show();
}
Here is the log.
java.lang.NoClassDefFoundError: Failed resolution of:Landroid/content/pm/ShortcutManager;
at com.zengtianyu.gallery1.DetailLSW.onCreate(DetailLSW.java:88)
at android.app.Activity.performCreate(Activity.java:6323)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2518)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5544)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.content.pm.ShortcutManager" on path: DexPathList[[zip file "/data/app/com.zengtianyu.gallery1-1/base.apk"],nativeLibraryDirectories=[/data/app/com.zengtianyu.gallery1-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 14 more
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.content.pm.ShortcutManager" on path: DexPathList[[dex file "/data/dalvik-cache/xposed_XResourcesSuperClass.dex"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Suppressed: java.lang.ClassNotFoundException:android.content.pm.ShortcutManager
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
You are passing ShortcutManager.class instead of the string constant SHORTCUT_SERVICE
Change line 8 to the following:
shortcutManager = (ShortcutManager)getSystemService(SHORTCUT_SERVICE);
If you wish to support older android versions, don't make shortcutManager a global variable and instead create it in the addShortcut() function and wrapping the usage of the function inside the sdk version check on line 7
So you should end up with:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
addShortcut();
}
...
public void addShortcut(){
ShortcutManager shortcutManager = (ShortcutManager)getSystemService(SHORTCUT_SERVICE);
...
}
I am getting BadParcelableException when reading a String from the bundle. This happens only on the release version of APK.
I have added these rules on proguard-rules.pro, but still getting the same error.
proguard-rules.pro
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
Stacktrace for the error:
Process: com.sample.app, PID: 15083 android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.sample.checkout.j
at android.os.Parcel.readParcelableCreator(Parcel.java:2304)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readListInternal(Parcel.java:2526)
at android.os.Parcel.readArrayList(Parcel.java:1842)
at android.os.Parcel.readValue(Parcel.java:2173)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.get(BaseBundle.java:280)
at com.sample.mp.checkout.SampleService.a(Unknown Source)
at com.sample.mp.checkout.t$1.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Any help on what could be causing this error?
Resolved by adding #SerializedName annotation to the object variables.