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
Related
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
After Adding the Ad Mob in App , its working in higher version above 5.0 but its not working in 4.0 , i am getting the following exception
java.lang.RuntimeException: Unable to instantiate service g2eandroid.srs.service.MyFirebaseInstanceIDService: java.lang.ClassNotFoundException: Didn't find class "g2eandroid.srs.service.MyFirebaseInstanceIDService" on path: DexPathList[[zip file "/data/app/g2eandroid.srs-2.apk"],nativeLibraryDirectories=[/data/app-lib/g2eandroid.srs-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2570)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "g2eandroid.srs.service.MyFirebaseInstanceIDService" on path: DexPathList[[zip file "/data/app/g2eandroid.srs-2.apk"],nativeLibraryDirectories=[/data/app-lib/g2eandroid.srs-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2567)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Please create a class
import android.content.Context;
import android.support.multidex.MultiDexApplication;
public class EnableMultiDex extends MultiDexApplication {
private static EnableMultiDex enableMultiDex;
public static Context context;
public EnableMultiDex(){
enableMultiDex=this;
}
public static EnableMultiDex getEnableMultiDexApp() {
return enableMultiDex;
}
#Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
}
and in your manifest give android:name="packagename.EnableMultiDex"
eg:
<application
android:name="YourPakageName.EnableMultiDex"
android:hardwareAccelerated="true"
android:icon="#drawable/wowio_launch_logo"
android:label="#string/app_name"
android:largeHeap="true"
tools:node="replace">
Let me know whether it solved your issue.
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
I'm trying to get Buck working with the balnk application template from Android Studio.
apps/snappy/BUCK
android_binary(
name = 'main',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:debug',
package_type = 'debug',
deps = [
'//java:main',
'//res:res',
'//keystores:debug',
],
)
res/snappy/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.whitedrop.snappy.MainActivity">
....
</android.support.design.widget.CoordinatorLayout>
res/BUCK
android_resource(
name = 'res',
res = 'snappy',
package = 'com.whitedrop.snappy',
deps = [
'//libs:appcompat-v7',
'//libs:design'
],
visibility = [
'PUBLIC',
]
)
libs/BUCK
android_prebuilt_aar(
name = 'appcompat-v7',
aar = 'appcompat-v7-23.0.1.aar',
visibility = ['PUBLIC']
)
android_prebuilt_aar(
name = 'design',
aar = 'design-23.0.1.aar',
visibility = ['PUBLIC']
)
output
Process com.whitedrop.snappy created for activity com.whitedrop.snappy/.MainActivity
PID: 2449 UID: GIDs:
ActivityManager I Start proc 2449:com.whitedrop.snappy/u0a61 for activity com.whitedrop.snappy/.MainActivity
art I Rejecting re-init on previously-failed class java.lang.Class<android.support.design.widget.CoordinatorLayout>
AndroidRuntime D Shutting down VM
E FATAL EXCEPTION: main
E Process: com.whitedrop.snappy, PID: 2449
E java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whitedrop.snappy/com.whitedrop.snappy.MainActivity}: android.view.InflateExcept
ion: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
...E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
....
E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E ... 10 more
E Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data
/app/com.whitedrop.snappy-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
...
E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
E ... 19 more
E Suppressed: java.lang.NoClassDefFoundError: android.support.design.widget.CoordinatorLayout
E at dalvik.system.DexFile.defineClassNative(Native Method)
E .... at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E ... 23 more
E Suppressed: java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout
E at java.lang.Class.classForName(Native Method)
E at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E ... 22 more
E Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
ActivityManager W Force finishing activity 1 com.whitedrop.snappy/.MainActivity
EDIT: my apk contains the CoordinatorLayout class in its dex file btw
EDIT2: full code can be found here https://github.com/vinz243/snappy
EDIT3: tried extending from AppCompatActivity:
vinz243#vm:~/snappy$ buck build app
[-] PROCESSING BUCK FILES...FINISHED 0.1s [100%]
[+] DOWNLOADING... (0.00 B/S, TOTAL: 0.00 B, 0 Artifacts)
[+] BUILDING...0.3s [67%] (16/20 JOBS, 0 UPDATED, 0.0% CACHE MISS)
|=> IDLE
|=> IDLE
|=> //java:main... 0.2s (running javac[0.2s])
|=> IDLE
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:12: error: cannot access android.support.v4.app.TaskStackBuilder
public class MainActivity extends AppCompatActivity {
^
class file for android.support.v4.app.TaskStackBuilder not found
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:14: error: method does not override or implement a method from a supertype
#Override
^
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:16: error: cannot find symbol
super.onCreate(savedInstanceState);
^
symbol: variable super
location: class com.whitedrop.snappy.MainActivity
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:17: error: cannot find symbol
setContentView(R.layout.activity_main);
^
symbol: method setContentView(int)
location: class com.whitedrop.snappy.MainActivity
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:20: error: method does not override or implement a method from a supertype
#Override
^
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:23: error: cannot find symbol
getMenuInflater().inflate(R.menu.activity_main, menu);
^
symbol: method getMenuInflater()
location: class com.whitedrop.snappy.MainActivity
Errors: 6. Warnings: 0.
Here is the MainActivity.java:
package com.whitedrop.snappy;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
EDIT 5:
Fixed above error by adding support v4 to deps. Now I get when running:
E java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whitedrop.snappy/com.whitedrop.snappy.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
E Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
E at android.view.LayoutInflater.createView(LayoutInflater.java:633)
E Caused by: java.lang.reflect.InvocationTargetException
E at java.lang.reflect.Constructor.newInstance(Native Method)
E at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
E at android.view.LayoutInflater.createView(LayoutInflater.java:607)
E ... 24 more
E Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/graphics/drawable/VectorDrawableCompat;
E at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:891)
E Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.graphics.drawable.VectorDrawableCompat" on path: DexPathList[[zip file
"/data/app/com.whitedrop.snappy-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
Make sure the versions you've mentioned in your BUCK config are correct.
In the code you've shared in your question i see v23.0.1 for support and design libraries. In your github repository I see v23.4.0.
I'm suspecting this is the reason. Change to the correct version you've included in your libs folder and see if it works.
Update in response to edit 5 in your question:
The following two dependencies will help resolve the VectorDrawableCompat ClassNotFoundException. Include them in a suitable way for BUCK.
compile 'com.android.support:support-vector-drawable:23.4.0'
compile 'com.android.support:animated-vector-drawable:23.4.0'
Try extending MainActivity to AppCompatActivity instead of Activity
And then a clean install.
Not related to BUCK but for me, I came across this error when using a mix of androidx and android.support.v7 libraries. See my solution for that version of this error here: https://stackoverflow.com/a/52490825/1762493