我正在更新我的应用程序以便与Java 8兼容。因此,我正在使用jack编译器。
这对于每个具有Android 5.0或更高版本的设备都完美地工作。在旧版Pre Lollipop设备上,我遇到了以下异常:
由于:java.lang.ClassNotFoundException: 在路径上未找到类“de.gelbeseiten.android.GelbeSeitenApplication”: DexPathList[[zip文件“/data/app/de.gelbeseiten.android-1.apk”],nativeLibraryDirectories=[/data/app-lib/de.gelbeseiten.android-1,/vendor/lib,/system/lib,/system/lib/arm]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)中引起 在java.lang.ClassLoader.loadClass(ClassLoader.java:497)中加载类 在java.lang.ClassLoader.loadClass(ClassLoader.java:457)中加载类 在android.app.Instrumentation.newApplication(Instrumentation.java:981)中 在android.app.LoadedApk.makeApplication(LoadedApk.java:511)中创建应用程序 在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4722)中处理绑定应用程序 在android.app.ActivityThread.access$1600(ActivityThread.java:172)中访问 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)中 在android.os.Handler.dispatchMessage(Handler.java:102)中分发消息 在android.os.Looper.loop(Looper.java:146)中循环 在android.app.ActivityThread.main(ActivityThread.java:5653)中 在java.lang.reflect.Method.invokeNative(Native Method)中调用反射方法 在java.lang.reflect.Method.invoke(Method.java:515)中调用方法
我99%确定,这是Java 8的改变导致的,如果我只检出当前公共版本并仅包括Java 8,则会发生这种情况。
不幸的是,我在谷歌上找不到任何有关此事的信息。在谷歌Android网站上,有关Java 8支持的页面中,并没有写明需要最低的Android版本。 https://developer.android.com/guide/platform/j8-jack.html 我认为完整的build.gradle文件并没有用处,但这里有一段代码片段:
Stackoverflow将文件的一部分显示为注释,但在我的Android Studio中的proguard文件中并非如此。
那么...有人对这个话题有更多的信息吗?或者甚至有一个修复方案可以使应用程序在Pre L设备上运行吗?
提前致谢! Ben
这对于每个具有Android 5.0或更高版本的设备都完美地工作。在旧版Pre Lollipop设备上,我遇到了以下异常:
由于:java.lang.ClassNotFoundException: 在路径上未找到类“de.gelbeseiten.android.GelbeSeitenApplication”: DexPathList[[zip文件“/data/app/de.gelbeseiten.android-1.apk”],nativeLibraryDirectories=[/data/app-lib/de.gelbeseiten.android-1,/vendor/lib,/system/lib,/system/lib/arm]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)中引起 在java.lang.ClassLoader.loadClass(ClassLoader.java:497)中加载类 在java.lang.ClassLoader.loadClass(ClassLoader.java:457)中加载类 在android.app.Instrumentation.newApplication(Instrumentation.java:981)中 在android.app.LoadedApk.makeApplication(LoadedApk.java:511)中创建应用程序 在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4722)中处理绑定应用程序 在android.app.ActivityThread.access$1600(ActivityThread.java:172)中访问 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)中 在android.os.Handler.dispatchMessage(Handler.java:102)中分发消息 在android.os.Looper.loop(Looper.java:146)中循环 在android.app.ActivityThread.main(ActivityThread.java:5653)中 在java.lang.reflect.Method.invokeNative(Native Method)中调用反射方法 在java.lang.reflect.Method.invoke(Method.java:515)中调用方法
我99%确定,这是Java 8的改变导致的,如果我只检出当前公共版本并仅包括Java 8,则会发生这种情况。
不幸的是,我在谷歌上找不到任何有关此事的信息。在谷歌Android网站上,有关Java 8支持的页面中,并没有写明需要最低的Android版本。 https://developer.android.com/guide/platform/j8-jack.html 我认为完整的build.gradle文件并没有用处,但这里有一段代码片段:
android {
useLibrary 'org.apache.http.legacy'
defaultConfig {
[...]
multiDexEnabled = true
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
我从未手动更改过proguard-rules.txt文件,但是这里有它的内容:
# Add project specific ProGuard rules here.
# By teilnehmer, the flags in this file are appended to flags specified
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
##---------------Begin: proguard configuration common for all Android apps ----------
-dontobfuscate
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses
-libraryjars libs
# The official support library.
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
# Library JARs.
-keep class de.greenrobot.dao.** { *; }
-keep interface de.greenrobot.dao.** { *; }
-keep class org.joda.** { *; }
-keep interface org.joda.** { *; }
-keep class com.loopj.android.http.** { *; }
-keep interface com.loopj.android.http.** { *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
# Espress: java.lang.NoSuchMethodError: android.support.test.espresso.Espresso
-keep class android.support.v7.widget.RecyclerView { *; }
# adjust
-keep class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.** { *; }
-keep class com.google.android.gms.ads.identifier.** { *; }
-keep class com.adjust.sdk.plugin.MacAddressUtil {
java.lang.String getMacAddress(android.content.Context);
}
-keep class com.adjust.sdk.plugin.AndroidIdUtil {
java.lang.String getAndroidId(android.content.Context);
}
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo (android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId ();
boolean isLimitAdTrackingEnabled();
}
#keep all classes that might be used in XML layouts
-keep public class * extends android.view.View
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.Fragment
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
##---------------End: proguard configuration common for all Android apps ----------
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by teilnehmer, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
Stackoverflow将文件的一部分显示为注释,但在我的Android Studio中的proguard文件中并非如此。
那么...有人对这个话题有更多的信息吗?或者甚至有一个修复方案可以使应用程序在Pre L设备上运行吗?
提前致谢! Ben