After updating the project gradle wrapper from 2.14.1 to 3.3 and Android gradle plugin from 2.2.3 to 2.3.1 I have a ClassNotFoundException on the wearable application start.
Notes:
- If the wearable app pushed directly from the Android Studio to the watch, and not as the part of the mobile release APK, everything works ok.
- On the previous gradle version no exceptions.
Exception:
04-12 15:54:57.824 18000-18000/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.artyom.aa.artyom.android, PID: 18000 java.lang.RuntimeException: Unable to instantiate application com.artyom.aa.artyom.android.MyWearApplication: java.lang.ClassNotFoundException: Didn't find class "com.artyom.aa.artyom.android.MyWearApplication" on path: DexPathList[[zip file "/system/framework/com.google.android.wearable.jar", zip file "/data/app/com.artyom.aa.artyom.android-1/base.apk"],nativeLibraryDirectories=[/data/app/com.artyom.aa.artyom.android-1/lib/arm, /vendor/lib, /system/lib]] at android.app.LoadedApk.makeApplication(LoadedApk.java:578) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685) 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:5422) 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.artyom.aa.artyom.android.MyWearApplication" on path: DexPathList[[zip file "/system/framework/com.google.android.wearable.jar", zip file "/data/app/com.artyom.aa.artyom.android-1/base.apk"],nativeLibraryDirectories=[/data/app/com.artyom.aa.artyom.android-1/lib/arm, /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:981) at android.app.LoadedApk.makeApplication(LoadedApk.java:573) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685) 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:5422) 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) Suppressed: java.lang.ClassNotFoundException: com.artyom.aa.artyom.android.MyWearApplication 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) ... 12 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Wearable build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
def serverVersion = project.file("../server_version.txt").text
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.artyom.aa.artyom.android"
minSdkVersion 21
targetSdkVersion 25
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
signingConfigs {
release {
storeFile file(project.ext.releaseStoreFile)
storePassword project.ext.releaseStorePassword
keyAlias project.ext.releaseKeyAlias
keyPassword project.ext.releaseKeyPassword
}
debug {
storeFile file(project.ext.debugStoreFile)
storePassword project.ext.debugStorePassword
keyAlias project.ext.debugKeyAlias
keyPassword project.ext.debugKeyPassword
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
//TODO should be removed in production
multiDexEnabled true
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
}
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.google.android.support:wearable:2.0.1'
provided 'com.google.android.wearable:wearable:2.0.1'
compile 'com.google.android.gms:play-services-wearable:10.0.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
compile 'com.google.dagger:dagger:2.8'
provided 'javax.annotation:jsr250-api:1.0'
compile project(':shared')
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.shahar2k5:androidutils:1.0.1'
testCompile 'junit:junit:4.12'
// Rx import
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile("com.artyom.aa:smoove-mobile-dto_2.11:$serverVersion") {
transitive = false //do not bring dependant jars
changing = true
}
compile("com.artyom.aa:SmooveMobileLogicLayer:$serverVersion") {
transitive = false //do not bring dependant jars
changing = true
}
compile("com.artyom.aa:SmooveDataModel:$serverVersion") {
changing = true
}
compile 'com.artyom.aa:SmooveLogging:0.0.1-SNAPSHOT'
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile('com.github.tony19:logback-android-classic:1.1.1-6') {
// workaround issue #73
exclude group: 'com.google.android', module: 'android'
}
}
Application build.gradle:
apply plugin: 'maven'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'android-aspectj'
apply plugin: "org.sonarqube"
apply plugin: 'me.tatarka.retrolambda'
def buildVersion = project.file("../version.txt").text
def serverVersion = project.file("../server_version.txt").text
android {
project.group = 'com.artyom.aa'
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.artyom.aa.artyom.android"
buildConfigField 'String', "PEBBLE_APP_UUID", project.ext.pebbleAppUUID
minSdkVersion 19
targetSdkVersion 22
versionCode 70
multiDexEnabled true
versionName buildVersion
multiDexKeepProguard file("proguard-rules.pro")
ndk {
moduleName "accelerometer_ndk"
// This is the name of the module as defined in jni/Android.mk
cFlags "-DANDROID_NDK -D_DEBUG" // Define some macros
ldLibs "log", "android" //load .so files from ndk's usr\lib
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g" //specify the heap size for the dex process
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
signingConfigs {
release {
storeFile file(project.ext.releaseStoreFile)
storePassword project.ext.releaseStorePassword
keyAlias project.ext.releaseKeyAlias
keyPassword project.ext.releaseKeyPassword
}
debug {
storeFile file(project.ext.debugStoreFile)
storePassword project.ext.debugStorePassword
keyAlias project.ext.debugKeyAlias
keyPassword project.ext.debugKeyPassword
}
}
buildTypes {
release {
buildConfigField 'boolean', "REPORT_CRASHES", 'true'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"artyom.apk")
}
}
}
debug {
ndk {
debuggable = true
}
versionNameSuffix "_DEV"
buildConfigField 'boolean', "REPORT_CRASHES", 'false'
minifyEnabled false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"artyom.apk")
}
}
}
daily {
versionNameSuffix "_" + getDate()
debuggable true //TODO should be removed in production
buildConfigField 'boolean', "REPORT_CRASHES", 'true'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"artyom.apk")
}
}
}
}
lintOptions {
abortOnError false
}
sourceSets {
test {
java.srcDirs = ['src/test/java/']
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
tasks.withType(Test) {
maxParallelForks = 1
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:25.1.0'
resolutionStrategy.force 'com.google.guava:guava:20.0'
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'com.squareup.assertj:assertj-android:1.1.0'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'org.robolectric:shadows-multidex:3.0'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.3'
//Validation dependencies
//Dependency Injection
provided 'org.roboguice:roboblender:3.0.1'
//Logging decencies
compile('com.github.tony19:logback-android-classic:1.1.1-3') {
exclude group: 'com.google.android', module: 'android'
}
compile("com.artyom.aa:SmooveAnalyticsCore:$serverVersion") {
exclude group: 'org.slf4j'
exclude group: 'log4j'
changing = true
}
compile("com.artyom.aa:SmooveAndroidImpl:$serverVersion") {
exclude module: 'SmooveDataModel'
exclude group: 'org.slf4j'
exclude group: 'log4j'
changing = true
}
compile("com.artyom.aa:SmooveDataModel:$serverVersion") {
transitive = false //do not bring dependant jars
changing = true
}
/* TODO: Remove the below jackson dependencies when data model will be in separate jar*/
compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
transitive = true;
exclude group: 'junit'
}
//Build fix workaround - http://forums.gradle.org/gradle/topics/pom-dependency-excludes-wildcard-excluding-the-dependency-itself
//Caused by Robolectric dependency
compile('org.apache.maven:maven-ant-tasks:2.1.3') {
transitive = false;
}
// Android Wear dependencies
wearApp project(':wear')
compile project(':shared')
compile 'com.google.android.gms:play-services-wearable:10.0.1'
compile 'com.github.shahar2k5:androidutils:1.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
//compile 'com.google.android.gms:play-services-analytics:7.8.0'
compile 'javax.el:javax.el-api:2.2.4'
compile 'org.hibernate:hibernate-validator:5.1.3.Final'
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.getpebble:pebblekit:3.0.0'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.jjoe64:graphview:4.0.1'
compile 'joda-time:joda-time:2.3'
compile 'org.roboguice:roboguice:3.0.1'
compile 'com.github.tony19:logback-android-core:1.1.1-3'
compile 'org.slf4j:slf4j-api:1.7.6'
compile("com.artyom.aa:SmooveLogging:$serverVersion") { changing = true }
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.2'
compile 'com.android.support:support-v4:25.1.0'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.google.guava:guava:20.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
}
//tasks.whenTaskAdded { task ->
// if (task.name in ['assembleRelease', 'assembleDaily']) {
// task.dependsOn 'test'
// }
//}
def getDate() {
def date = new Date()
def formattedDate = date.format('yyyy-MM-dd-HHmm')
return formattedDate
}