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.
I have added AAR file in libs folder of my main project and compiled the same in build.gradle.
1) Do I need to add multi-dex support in both library as well as main android project?
2) Do I need to add afterEvaluate script in both project?
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.
Edits :- I am trying to keep posting updates based on my testing so anyone who has any idea can help all of us.
dependencies used in project :-
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 - As per the documentation I modified my code and its working now, but I am unable to generate signed apk with 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;
}
Errors :-
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.
Any ideas?
First of all, check out the official documentation - it explains how to add multi-dex support in great detail.
Answers:
Do I need to add multi-dex support in both library as well as main android project?
Specify 'multiDexEnabled = true' (under defaultConfig) only in main Android project. No need to declare it in libraries.
Do I need to add afterEvaluate script in both project?
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.
Post the results, and let us know if you still have ClassNotFoundException errors.
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
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.**
Note that your proguard config is missing the org.apache.commons.logging.** entry.
来源:https://stackoverflow.com/questions/32003870/too-many-method-references-in-android-library-project-classnotfoundexception