将项目gradle包装器从2.14.1更新到3.3并将Android gradle插件从2.2.3更新到2.3.1后,我在可穿戴应用程序启动时遇到了ClassNotFoundException .
笔记:
-
如果可穿戴应用程序直接从Android Studio推送到 Watch ,而不是移动版APK的一部分,那么一切正常 .
-
在以前的gradle版本上没有例外 .
例外:
04-12 15:54:57.824 18000-18000 /? E / AndroidRuntime:FATAL EXCEPTION:main进程:com.artyom.aa.artyom.android,PID:18000 java.lang.RuntimeException:无法实例化应用程序com.artyom.aa.artyom.android.MyWearApplication:java.lang.ClassNotFoundException :没有在路径上找到类“com.artyom.aa.artyom.android.MyWearApplication”:DexPathList [[zip文件“/system/framework/com.google.android.wearable.jar”,zip文件“/ data / app / com.artyom.aa.artyom.android-1 / base.apk“],nativeLibraryDirectories = [/ data / app / com.artyom.aa.artyom.android-1 / lib / arm,/ vendor / lib,/系统/ lib]]在Android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685)的android.app.LoadedApk.makeApplication(LoadedApk.java:578)android.app.ActivityThread.-wrap1(ActivityThread.java)at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1405)在android.app.Handler.dispatchMessage(Handler.java:102)android.app.Looper.loop(Looper.java:148)android.app java.lang.reflect中的.ActivityThread.main(ActivityThread.java:5422) . com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)的com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)中的Method.invoke(Native Method)引起: java.lang.ClassNotFoundException:在路径上找不到类“com.artyom.aa.artyom.android.MyWearApplication”:DexPathList [[zip file“/system/framework/com.google.android.wearable.jar”,zip文件“/data/app/com.artyom.aa.artyom.android-1/base.apk"],nativeLibraryDirectories=[/data/app/com.artyom.aa.artyom.android-1/lib/arm,/在java.lang.ClassLoader.loadClass(ClassLoader)的java.lang.ClassLoader.loadClass(ClassLoader.java:511)的dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)上的vendor / lib,/ system / lib] .java:469)在android.app.Instrumentation.new应用程序中的android.app.Instrumentation.newApplication(Instrumentation.java:981)android.app.LoadedApk.makeApplication(LoadedApk.java:573) . (ActivityThread.java:4685)在android.app.ActivityThread.-wrap1(ActivityThread.java)at和在Android.app的android.os.Looper.loop(Looper.java:148)的android.os.Handler.dispatchMessage(Handler.java:102)的roid.app.ActivityThread $ H.handleMessage(ActivityThread.java:1405) .ActivityThread.main(ActivityThread.java:5422)位于com.android的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)的java.lang.reflect.Method.invoke(Native Method) .internal.os.ZygoteInit.main(ZygoteInit.java:616)压缩:java.lang.ClassNotFoundException:com.artyom.aa.artyom.android.MyWearApplication at java.lang.Class.classForName(Native Method)at java.lang .bootClassLoader.findClass(ClassLoader.java:781)java.lang.BootClassLoader.loadClass(ClassLoader.java:841)java.lang.ClassLoader.loadClass(ClassLoader.java:504)... 12更多引起:java .lang.NoClassDefFoundError:使用引导类加载器找不到类;没有堆栈跟踪可用
可穿戴的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'
}
}
应用程序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
}