android库项目中的方法引用太多 - ClassNotFoundException

时间:2015-08-14 06:46:14

标签: android android-library multidex android-proguard

我有使用AAR文件在主android项目中使用的库项目。我现在得到了我所期望的着名的65k方法限制,但我的查询很少。

我在主项目的libs文件夹中添加了AAR文件,并在build.gradle中编译了相同的文件。

1)我是否需要在库和主要android项目中添加multi-dex支持?

2)我是否需要在两个项目中添加afterEvaluate脚本?

最重要的是,如果我们得到了多dex工作,我们可能会遇到这样的问题:在主要的android项目中,如果我们尝试使用的任何类不在主dex列表中,我们会得到Classnotfound异常。

编辑: - 我正在尝试根据我的测试发布更新,因此任何有任何想法的人都可以帮助我们所有人。

项目中使用的

依赖项: -

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.android.gms:play-services-gcm:7.8.0'
    compile 'com.google.android.gms:play-services-location:7.8.0'
    compile 'com.google.android.gms:play-services-ads:7.8.0'
    compile 'co.pointwise:pw-proto:0.0.5'
    compile 'com.amazonaws:aws-android-sdk-sns:2.2.1'
    compile 'com.amazonaws:aws-android-sdk-core:2.2.1'
    compile 'com.github.tony19:logback-android-core:1.1.1-4'
    compile 'com.github.tony19:logback-android-classic:1.1.1-4'
    compile 'org.slf4j:slf4j-api:1.7.6'
    compile 'com.android.support:multidex:1.0.0'
    compile(name: 'sdk-debug', ext: 'aar') // my library project

    // Crashlytics Kit
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true
    }
}

17-08-2015 - 根据我修改我的代码及其工作的文档,但我无法使用proguard生成签名的apk。

Proguard文件如下: -

-keep class ch.qos.** { *; }
-keep class org.slf4j.** { *; }
-keep class io.protostuff.** { *; }
-keep class com.google.common.** { *; }
-keep com.amazonaws.http.** { *; }
-keep com.amazonaws.internal.** { *; }
-keepattributes *Annotation*

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

# Keep the names of classes/members we need for client functionality.
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

# Needed for Parcelable/SafeParcelable Creators to not get stripped
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

错误: -

Warning: com.amazonaws.AmazonWebServiceClient: can't find referenced class org.apache.commons.logging.LogFactory
Warning: ch.qos.logback.core.net.SMTPAppenderBase: can't find referenced class javax.mail.internet.MimeMessage
Warning: com.google.common.base.Absent: can't find referenced class javax.annotation.Nullable
Warning: there were 1406 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 9 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
:app:proguardProdRelease FAILED

我之前也遇到过这个问题,我无法在上一个项目中解决它,但这次我需要解决它。

有什么想法吗?

0 个答案:

没有答案