本文介绍了在Android的库项目太多方法参考 - ClassNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用AAR文件中使用主机器人项目,该项目库项目。我得到现在著名的65K方法限制我所预期的,但我有几个疑问。

I have library project which I am using in main android project using AAR file. I am getting the famous 65k method limit now which I have expected, but I have few queries.

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

I have added AAR file in libs folder of my main project and compiled the same in build.gradle.

1)我需要在这两个库中添加多DEX支持,以及主要的Andr​​oid项目?

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

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

2) Do I need to add afterEvaluate script in both project?

更重要的是,如果我们得到了多DEX的工作,我们可能得到的问题,主要在Android项目得到ClassNotFound的异常,如果其中任何一个,我们尝试使用类是不在主名单DEX

Most importantly if we got multi-dex working, we might get issue that in main android project we get Classnotfound exception if any of the class which we try to use is not in main dex list.

编辑: - 我想根据我的测试,以保持上发布更新,以便任何人谁有任何想法可以帮助我们所有的人

在项目中使用的依赖关系: -

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 - 根据文件我修改了code,现在它的工作,但我无法生成使用ProGuard签署的apk

17-08-2015 - As per the documentation I modified my code and its working now, but I am unable to generate signed apk with proguard.

Proguard的文件看起来像: -

Proguard file looks like :-

-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

我所面临的问题,前面还有,我是不是能够解决它的最后一个项目,但这个时候,我需要解决它。

I have faced the issue earlier as well, and i was not able to resolve it in last project but this time i need to solve it.

任何想法?

推荐答案

首先,检查出的 - 它说明了如何在非常详细添加多DEX支持

First of all, check out the official documentation - it explains how to add multi-dex support in great detail.

回答:

我是否需要添加两个库多DEX支持,以及主
  Android项目?

指定的'multiDexEnabled =真正的的(下的 defaultConfig 的),只能在主要的Andr​​oid项目。无需声明它在库中。

Specify 'multiDexEnabled = true' (under defaultConfig) only in main Android project. No need to declare it in libraries.

我需要在这两个项目中添加afterEvaluate脚本?

v0.14.0加入支持多DEX,你不再需要添加你所提到的code。该插件会自动创建主DEX列表,将所需的信息传递到DEX的过程。

v0.14.0 of Gradle plugin for Android added support for multi-dex and you no longer need to add the code that you mentioned. The plugin will automatically create the main dex list and will pass the required information to dex process.

后的结果,让我们知道,如果你仍然有ClassNotFoundException的错误。

Post the results, and let us know if you still have ClassNotFoundException errors.

我试图建立一个版本时收到以下错误
  变种使用ProGuard:结果
  警告:com.amazonaws.AmazonWebServiceClient:
  找不到引用的类org.apache.commons.logging.LogFactory

在他们的,AWS作者包括的如何设置ProGuard的配置:

In their github repo, AWS authors included instructions for how to setup proguard configuration:

-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 **项。

Note that your proguard config is missing the org.apache.commons.logging.** entry.

这篇关于在Android的库项目太多方法参考 - ClassNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:35