Не удалось найти байт-код для Volley при использовании его в библиотеке Android AAR - PullRequest
0 голосов
/ 19 сентября 2018

Я использую Volley в проекте библиотеки, который встроил в файл AAR.

Я добавляю файл 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.*

Любые советы о том, что может быть причиной этого?

Обновление : я пробовал это https://stackoverflow.com/a/27052696/1020311 относительно файла consumerProguardFiles Proguard, но я все еще получаю ту же ошибку при сборке основного проекта.

Я также пробовал по умолчанию *Файл 1022 * вместе с моими линиями залпа:

#
# 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.*

Кроме того, я попытался закомментировать строки 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'
}

Не могу ли я сделать файл AAR неправильным?

Спасибо!

Ответы [ 2 ]

0 голосов
/ 27 сентября 2018

лучше закомментируйте -dontwarn и добавьте -verbose (сверху) при тестировании правил.

... требуемое правило может быть либо:

-keep,includedescriptorclasses class com.android.volley.** { *; }

, либос двумя ** (то же самое относится ко всем другим записям, с одним *):

-keep class com.android.volley.Response$** { *; }

это может быть даже явно прописано, например:

-keep class com.android.volley.Response$Listener { *; }

примерно так:

-keepattributes *Annotation*

-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$** { *; }
#-dontwarn com.android.volley.error.**
#-dontwarn com.android.volley.**

# not sure if this one is required
#-keep interface com.android.volley.** { *; }

-keep class org.apache.commons.logging.**
#-dontwarn org.apache.**
0 голосов
/ 26 сентября 2018

Не удалось найти байт-код для com/android/volley/Response$Listener

Что меня беспокоило, так это:

consumerProguardFiles 'proguard-library.pro'

Вы использовали эту строку кода в блоках release и defaultConfig, и я считаю, что это вызывает проблему.

Проверьте комментарий:

consumerProguardFiles следует указывать в defaultConfig , а не buildTypes / release , чтобы оно работало, если приложение-потребитель продолжает работать как в режиме отладки, так и в режиме выпуска (например, чтобы избежать использования метода dek 65k)предел)

PS: Правила Progaurd, похоже, не проблема.По крайней мере, вы можете попробовать обновить Appcompat, затем протестировать проект, а также я создал тестовый проект, и он работал с вашими текущими кодами.

...