其他分享
首页 > 其他分享> > android库项目中的方法引用太多 – ClassNotFoundException

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

作者:互联网

我有使用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

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

有任何想法吗?

解决方法:

首先,查看official documentation – 它解释了如何非常详细地添加multi-dex支持.

回答:

Do I need to add multi-dex support in both library as well as main
android project?

仅在主Android项目中指定’multiDexEnabled = true'(在defaultConfig下).无需在库中声明它.

Do I need to add afterEvaluate script in both project?

适用于Android的Gradle插件v0.14.0增加了对multi-dex的支持,您不再需要添加您提到的代码.该插件将自动创建主dex列表,并将所需信息传递给dex进程.

发布结果,如果您仍然有ClassNotFoundException错误,请告诉我们.

I’m receiving the following error when trying to build a release
variant with proguard:
Warning: com.amazonaws.AmazonWebServiceClient:
can’t find referenced class org.apache.commons.logging.LogFactory

在其github repo中,AWS作者在instructions中介绍了如何设置proguard配置:

-keep class org.apache.commons.logging.**               { *; }
-keep class com.amazonaws.services.sqs.QueueUrlHandler  { *; }
-keep class com.amazonaws.javax.xml.transform.sax.*     { public *; }
-keep class com.amazonaws.javax.xml.stream.**           { *; }
-keep class com.amazonaws.services.**.model.*Exception* { *; }
-keep class com.amazonaws.internal.**                   { *; }
-keep class org.codehaus.**                             { *; }
-keep class org.joda.convert.*                          { *; }
-keepattributes Signature,*Annotation*,EnclosingMethod
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class com.amazonaws.** { *; }

-dontwarn com.amazonaws.auth.policy.conditions.S3ConditionFactory
-dontwarn org.joda.time.**
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn javax.xml.stream.events.**
-dontwarn org.codehaus.jackson.**
-dontwarn org.apache.commons.logging.impl.**
-dontwarn org.apache.http.conn.scheme.**
-dontwarn org.apache.http.annotation.**
-dontwarn org.ietf.jgss.**
-dontwarn org.w3c.dom.bootstrap.**

请注意,您的proguard配置缺少org.apache.commons.logging.**条目.

标签:android,android-library,multidex,android-proguard
来源: https://codeday.me/bug/20190706/1399280.html