ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-06 18:26:10  阅读:303  来源: 互联网

标签: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

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

有任何想法吗?

解决方法:

首先,查看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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有