NoClassDefFoundError on android emualtors when enable instant run - android

This has been an issues for me for a while. I think it is related to APK split feature introduced in the latest Android Studio version.
05-22 09:22:21.274 3451-3451/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: android.zeroarst.lab.sharedelement, PID: 3451
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{android.zeroarst.lab.sharedelement/android.zeroarst.lab.sharedelement.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "android.zeroarst.lab.sharedelement.MainActivity" on path: DexPathList[[zip file "/data/app/android.zeroarst.lab.sharedelement-2/base.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_dependencies_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_0_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_1_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_2_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_3_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_4_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_5_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_6_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_7_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_8_apk.apk", zip file "/data/app/android.zeroarst.lab.sharedelement-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/android.zeroarst.lab.sharedelement-2/lib/x86_64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
There are more but they are all the same exceptions.
If I disabled instant run then everything is just fine.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "android.zeroarst.lab.sharedelement"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}

Related

NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx

I am using
pub.devrel:easygoogle:0.2.5
and
com.google.firebase:firebase-core:16.0.1
I am making a simple notification app which sends notification from FCM.
I am following this but at runtime i am getting error
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx;
at com.google.android.gms.measurement.internal.zzt.zzaU(Unknown Source)
at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source)
at com.google.firebase.analytics.connector.AnalyticsConnectorImpl.getInstance(Unknown Source)
at com.google.firebase.analytics.connector.internal.zzb.create(Unknown Source)
at com.google.firebase.components.zzh.zza(SourceFile:28)
at com.google.firebase.components.zzi.get(Unknown Source)
at com.google.firebase.components.zzh.get(SourceFile:39)
at com.google.firebase.components.ComponentContainer$$CC.get(Unknown Source)
at com.google.firebase.components.zzd.get(SourceFile)
at com.google.firebase.components.zzd.zza(SourceFile:68)
at com.google.firebase.FirebaseApp.zze(SourceFile:703)
at com.google.firebase.FirebaseApp.initializeApp(SourceFile:328)
at com.google.firebase.FirebaseApp.initializeApp(SourceFile:294)
at com.google.firebase.FirebaseApp.initializeApp(SourceFile:281)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(SourceFile:37)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(SourceFile:31)
at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzx" on path: DexPathList[[zip file "/data/app/com.apneareamein.autostartapp-1/base.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.apneareamein.autostartapp-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.apneareamein.autostartapp-1/lib/x86, /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 com.google.android.gms.measurement.internal.zzt.zzaU(Unknown Source) 
... 30 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
gradle file -
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.myapp.autostart"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.+'
compile 'com.android.support:support-v4:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
compile 'pub.devrel:easygoogle:0.2.5'
compile 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
I have added build gradle file for more details. i extended EasyMessageService for Notifications.
if any more details is required please let me know.
How can it be resolved?
Thanks in advance.
I had also like this problem. I had an old version google and other services such as google service 1.5.0-beta2 Wanted to run on android 10 devices and gave me an error.
Didn't find class "com.google.android.gms.common.internal.zzx"
Then I updated all libraries to the latest version. Then worked.

java.lang.RuntimeException: Unable to instantiate application on installation [duplicate]

This question already has answers here:
Instant Run throw DexIndexOverflowException
(3 answers)
Closed 5 years ago.
I am facing weird problem. When I install app via USB on phone, it works. But, when I transfer apk and install manually on mobile then it throws below error.
java.lang.RuntimeException: Unable to instantiate application com.xx.merchant.application.MerchantApplication: java.lang.ClassNotFoundException: Didn't find class "com.xx.merchant.application.MerchantApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:948)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5764)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xx.merchant.application.MerchantApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1086)
at android.app.LoadedApk.makeApplication(LoadedApk.java:942)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5764) 
at android.app.ActivityThread.-wrap1(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6540) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/multidex/MultiDexApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 12 more
09-21 16:33:04.565 14026-14026/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
My gradle file
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId 'com.xx.merchant'
minSdkVersion 17
targetSdkVersion 26
versionCode 7
versionName "1.0.7"
// Enabling multidex support.
multiDexEnabled true
}
signingConfigs {
release {
storeFile file('../keystore/xx.keystore')
storePassword 'xxx'
keyAlias "xxx"
keyPassword 'xxx'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
minifyEnabled false
}
}
productFlavors {
production {
applicationId "com.xx.merchant"
minSdkVersion 17
targetSdkVersion 26
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:cardview-v7:26.+'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:support-v13:26.+'
compile 'com.android.support:design:26.+'
}
apply plugin: 'com.google.gms.google-services'
Adds dependency to your gradle file
compile 'com.android.support:multidex:1.0.1'
also add MultiDex.install on your Application class
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

Caused by: java.lang.ClassNotFoundException: Could not find in any atom class loader or parent class loader

I am trying to do some experiments with Instant Apps Documentation: Android Instant Apps
Native Android apps, without the installation. I have followed steps which are covered on official docs. I have created emulator Nexus 5X to test instant apps features.
So, I have created two features in my project, which is much similar just kinda of demo to see how instant apps works. It was working well on one feature, now after when I created one more feature, now I have two features which in turns crashing my application.
05-24 12:07:12.259 12020-12028/? E/art: Failed writing handshake bytes (-1 of 14): Broken pipe
05-24 12:07:15.952 12020-12020/com.williams.instantappdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.williams.instantappdemo, PID: 12020
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.williams.instantappdemo/com.williams.instantappdemo.feature.MainActivity}: java.lang.ClassNotFoundException: could not find com.williams.instantappdemo.feature.MainActivity in any atom class loader or parent class loader
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: could not find com.williams.instantappdemo.feature.MainActivity in any atom class loader or parent class loader
at com.google.android.instantapps.supervisor.loader.WhAppClassLoader.loadClass(WhAppClassLoader.java:100)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.williams.instantappdemo.feature.MainActivity" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /vendor/lib, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.android.instantapps.supervisor.loader.WhAppClassLoader.loadClass(WhAppClassLoader.java:85)
... 11 more
Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.williams.instantappdemo.feature.MainActivity" on path: DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.williams.instantappdemo/atom-download--base-1495607829279/base.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.williams.instantappdemo, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at com.google.android.instantapps.supervisor.loader.DexFirstClassLoader.doLoadClass(DexFirstClassLoader.java:50)
at com.google.android.instantapps.supervisor.loader.WhAppClassLoader.loadClass(WhAppClassLoader.java:92)
... 11 more
Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.williams.instantappdemo.feature.MainActivity" on path: DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.williams.instantappdemo/atom-download--feature-1495607829279/feature.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.williams.instantappdemo, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at com.google.android.instantapps.supervisor.loader.DexFirstClassLoader.doLoadClass(DexFirstClassLoader.java:50)
at com.google.android.instantapps.supervisor.loader.WhAppClassLoader.loadClass(WhAppClassLoader.java:92)
... 11 more
Here is build.gradle of feature module:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':base')
testCompile 'junit:junit:4.12'
}
Here is build.gradle for feature2:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':base')
testCompile 'junit:junit:4.12'
}
Here is the build.gradle for base module:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion rootProject.buildToolsVersion
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
feature project(":feature1")
}
Here is the build.gradle of app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.nagarro.instantappdemo"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':feature')
implementation project(':feature1')
implementation project(':base')
}
Can anyone suggest what I am doing wrong ?
It looks like the actual activity package doesn't match what you have in your manifest file of the feature that contains MainActivity. It's a common error when refactoring activities into new packages and not using relative paths for activities in the manifest. Fully qualify the path to be absolutely sure
<activity android:name="com.williams.instantappdemo.feature.MainActivity"/>
Inspect the the apk file (build/outputs/apks) using Apk Analyzer to see if it has com.williams.instantappdemo.feature.MainActivity in that exact package.
You can also use the Merged Manifest view to inspect your final manifest (app module) to verify everything is in order.
Also, add application project(":app") to the base feature module so that it uses applicationId defined in your app module to package your app/instant app
Update:
Using the techniques described above, I investigated the merged manifests and found an issue. The build plugin ignored the numbers in the module name (feature1) so both features ended up having the same name. This caused a bunch of issues including the ActivityNotFound error. Renaming the feature1 module to featureOne resolved the issue.

ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path

I was working with some libraries so I had to edit Gradle settings. Since my app wasn't working, I restored it with Local history in Android studio but It still doesn't work. Errors returned are reported here
05-04 23:26:34.953 28017-28017/? I/art: Late-enabling -Xcheck:jni
05-04 23:26:35.217 28017-28017/com.quintabi.facchini.myshop W/System: ClassLoader referenced unknown path: /data/app/com.quintabi.facchini.myshop-2/lib/arm
05-04 23:26:35.233 28017-28017/com.quintabi.facchini.myshop I/InstantRun: starting instant run server: is main process
05-04 23:26:35.333 28017-28017/com.quintabi.facchini.myshop W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-04 23:26:35.465 28017-28017/com.quintabi.facchini.myshop D/AndroidRuntime: Shutting down VM
--------- beginning of crash
05-04 23:26:35.466 28017-28017/com.quintabi.facchini.myshop E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.quintabi.facchini.myshop, PID: 28017
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.quintabi.facchini.myshop/com.quintabi.facchini.myshop.index}: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.quintabi.facchini.myshop-2/base.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.quintabi.facchini.myshop-2/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.quintabi.facchini.myshop.index.onCreate(index.java:25)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
05-04 23:26:35.467 28017-28017/com.quintabi.facchini.myshop E/AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Build.gradle (Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.gradle(module):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.quintabi.facchini.myshop"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
Settings.gradle is just
include ':app'
You may have updated to AndroidX support library and the layout is referencing the old ConstraintLayout version. So you have to update the android.support.constraint.ConstraintLayout tags to androidx.constraintlayout.widget.ConstraintLayout in your layout XML.
Changes you have made earlier corrupted your Gradle File (the module one).
It should look like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "***" /*Your package name*/
minSdkVersion 15
targetSdkVersion 25
versionCode 5
versionName "1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
//Your Dependencies
//Don't forget to add dependency of constraint-layout
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Add dependency for constraint-layout.
See Code
NOTE : compile has become obsolete and replaced with 'implementation'
keyword so replace 'compile' with 'implementation'
so the code will be
dependencies {
//Your Dependencies
//Don't forget to add dependency of constraint-layout
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}
UPDATE: If you have upgraded to AndroidX now. Then you need to use androidx.constraintlayout.widget.ConstraintLayout instead of android.support.constraint.ConstraintLayout
use androidx.constraintlayout.widget.ConstraintLayout replace android.support.constraint.ConstraintLayout, then it worked
If you updated your project to Androidx
Then Change this dependency.
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
to
implementation 'androidx.constraintlayout.widget.ConstraintLayout:1.0.0'
This will work.

: Unable to instantiate application and ClassNotFound while sharing apk

when i run the app from android studio it runs fine in simulator and device.
but when i share the debug / release version of apk it got crashed when user taps on a app icon.
following the error that i can see in logs
03-11 09:16:12.654 25384-25384/com.microtechnicianapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.microtechnicianapp, PID: 25384
java.lang.RuntimeException: Unable to instantiate application com.microtechnicianapp.App: java.lang.ClassNotFoundException: Didn't find class "com.microtechnicianapp.App" on path: DexPathList[[zip file "/data/app/com.microtechnicianapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.microtechnicianapp-1/lib/x86, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:563)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.microtechnicianapp.App" on path: DexPathList[[zip file "/data/app/com.microtechnicianapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.microtechnicianapp-1/lib/x86, /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 android.app.Instrumentation.newApplication(Instrumentation.java:979)
at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491) 
at android.app.ActivityThread.access$1500(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5221) 
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:899) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
Suppressed: java.lang.ClassNotFoundException: com.microtechnicianapp.App
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)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
have read lot of threads but nothing works for me since morning.
have tried lot of things in gradle
apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'realm-android' android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.microtechnicianapp"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries false
} } repositories {
maven {
url "http://dl.bintray.com/lukaville/maven"
} }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.0.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.bluelinelabs:logansquare:1.3.6'
compile 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.github.gcacace:signature-pad:1.2.0'
compile 'com.github.davidpizarro:autolabelui:1.0.1'
compile 'com.nbsp:library:1.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
testCompile 'junit:junit:4.12'
apt 'com.bluelinelabs:logansquare-compiler:1.3.6'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.mikhaellopez:circularprogressbar:1.1.1'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
I am using android studio 2.3 hence gradle version is gradle-3.3-all.zip
I faced the same issue today, I have currently downgraded my gradle version and the generated debug apk works just fine, Feel like it might be an issue with the gradle version, will Update on this answer if i find with the actual issue.
But currently downgrading gradle from 2.3.0 to 2.2.0 seems to fix the issue.
I had the same crash with the debug apk of one of my apps. The release version (signed with release key) worked.
My app uses multidex.
I ended up disabling Instant Run in Android Studio (File -> Settings -> Build -> Instant Run) and after a rebuild the debug apk worked as well!
Found this solution here:
https://codentrick.com/cant-run-app-on-device-when-it-installed-from-debug-apk-file/

Categories

Resources