在Android库AAR中使用Volley时,无法找到Volley的字节代码

zun*_*ndi 9 android proguard android-volley android-proguard

我在一个我已经内置到AAR文件中的库项目中使用Volley.

我将AAR文件添加到主项目中.在构建主项目时,我收到以下错误:

Failed to find byte code for com/android/volley/Response$Listener

我猜它与Proguard配置有关,但即使我在创建AAR时构建调试变量,我也会收到错误.

这是我的图书馆项目的Proguard文件:

# Volley
-dontwarn com.android.volley.**
-dontwarn com.android.volley.error.**
-keep class com.android.volley.** { *; }
-keep class com.android.volley.toolbox.** { *; }
-keep class com.android.volley.Response$* { *; }
-keep class com.android.volley.Request$* { *; }
-keep class com.android.volley.RequestQueue$* { *; }
-keep class com.android.volley.toolbox.HurlStack$* { *; }
-keep class com.android.volley.toolbox.ImageLoader$* { *; }
-keep interface com.android.volley.** { *; }
-keep class org.apache.commons.logging.*
Run Code Online (Sandbox Code Playgroud)

有关可能导致此问题的任何提示?

更新:我已经尝试过这个关于Proguard文件的/sf/answers/1893688751/consumerProguardFiles,但在构建主项目时我仍然遇到同样的错误.

我还尝试了默认proguard-library.pro文件和我的排球线:

#
# This ProGuard configuration file illustrates how to process a program
# library, such that it remains usable as a library.
# Usage:
#     java -jar proguard.jar @library.pro
#

# Specify the input jars, output jars, and library jars.
# In this case, the input jar is the program library that we want to process.

# -injars  in.jar
# -outjars out.jar

# -libraryjars  <java.home>/lib/rt.jar

# Save the obfuscation mapping to a file, so we can de-obfuscate any stack
# traces later on. Keep a fixed source file attribute and all line number
# tables to get line numbers in the stack traces.
# You can comment this out if you're not interested in stack traces.

#-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                SourceFile,LineNumberTable,EnclosingMethod

# Preserve all annotations.

-keepattributes *Annotation*

# Preserve all public classes, and their public and protected fields and
# methods.

-keep public class * {
    public protected *;
}

# Preserve all .class method names.

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

# Preserve all native method names and the names of their classes.

-keepclasseswithmembernames class * {
    native <methods>;
}

# Preserve the special static methods that are required in all enumeration
# classes.

-keepclassmembers class * extends java.lang.Enum {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your library doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    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();
}

# Your library may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName:

# -keep public class mypackage.MyClass
# -keep public interface mypackage.MyInterface
# -keep public class * implements mypackage.MyInterface

# Volley
-dontwarn com.android.volley.**
-dontwarn com.android.volley.error.**
-keep class com.android.volley.** { *; }
-keep class com.android.volley.toolbox.** { *; }
-keep class com.android.volley.Response$* { *; }
-keep class com.android.volley.Request$* { *; }
-keep class com.android.volley.RequestQueue$* { *; }
-keep class com.android.volley.toolbox.HurlStack$* { *; }
-keep class com.android.volley.toolbox.ImageLoader$* { *; }
-keep interface com.android.volley.** { *; }
-keep class org.apache.commons.logging.*
Run Code Online (Sandbox Code Playgroud)

此外,我已经尝试评论Proguard线路buildTypes,因为该模块将是开源的,我不需要混淆,但仍然没有运气.

这是build.gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'proguard-library.pro'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-library.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.volley:volley:1.1.1'
}
Run Code Online (Sandbox Code Playgroud)

我可以将AAR文件弄错吗?

谢谢!

ʍѳђ*_*ઽ૯ท 2

找不到字节com/android/volley/Response$Listener

我所关心的事情是:

consumerProguardFiles 'proguard-library.pro'
Run Code Online (Sandbox Code Playgroud)

release您在和块中都使用了这行代码defaultConfig,我相信这会导致问题。

查看评论:

ConsumerProguardFiles应在 defaultConfig 中指定 ,而不是在 buildTypes/release中指定,以便在消费应用程序在调试和发布模式下进行混淆时它可以工作(例如,避免 65k dex 方法限制)

PS: Progaurd 规则似乎不是问题。至少,您可以尝试更新 Appcompat,然后测试该项目,我创建了一个测试项目,它适用于您当前的代码。