adwiv / android-fat-aar

Gradle script that allows you to merge and embed dependencies in generted aar file
The Unlicense
1.46k stars 435 forks source link

Possible option to '-dontwarn' feature #33

Closed williamlopes-dev closed 7 years ago

williamlopes-dev commented 7 years ago

I'm faced with 'small' problem. When I try build (assembleRelease) my library with (or not) enabled proguard configuration, the build process throws an exception because of some warnings. But I can't fix this issue from my own project, I need download your android-fat-aar.gradle file and edit by myself just adding the below code snippet on generateXClass method:

task generateXClass(type: ProGuardTask, dependsOn: generateRClass) {
    delete(post_r2x_dir)
    println generateXClass

    injars pree_r2x_dir, filter: '!**/R.java'
    outjars post_r2x_dir
    libraryjars android.getBootClasspath()
    libraryjars libraryPaths
    dontshrink
    dontoptimize
    dontpreverify
    dontwarn 'my.package.**' <<<
    dontwarn '**.R'
    dontwarn '**.R$*'
    keep 'class !**.R {*;}'
    keep 'class !**.R$* {*;}'
    applymapping "$base_r2x_dir/mapping-r.txt"
    printmapping "$base_r2x_dir/mapping.txt"
    printconfiguration "$base_r2x_dir/config.txt"
}

I believe that you can add a config file to create a way of to configure your internal proguard. Or I'm wrong and already exists a right way to do this?

Thanks in advance!

adwiv commented 7 years ago

Hi,

If possible can you please share the warnings you get? Maybe that points to a bug in fat-aar gradle file.

There isn't a way currently to include an external proguard file for remapping the R class, although it would surely be possible to do so. Theoretically I can add something like don't warn **, but that would be so wrong 😊

Since we rename only one file per module, I was thinking that we should be able to generate the exact config for our needs. If you can let us know the errors, maybe we can fix or note that down in the known issues.

Cheers.

williamlopes-dev commented 7 years ago

Hi,

I'll try explain, in the truth just now I understand my real problem.

I'm using your gradle script since begin of last year, but I stayed 15 days without to work on my Android project. Last week I formatted my ubuntu system, therefore I installed all newest versions of applications to work, such as Android Studio 2.2 and JDK 1.8. Today when I ran assembleReselease, I note that your script is running the proguard process again (unduly?).

My minifyEnabled is setted to false, but still running proguard process when I call assembleRelease. And this didn't happened before.

I have multiples projects that are joined by com.github.dcendents.android-maven plugin, in this projects really uses minifyEnabled setted as true, but on main project that generate final lib don't.

The warning generated: Warning: com.package.Foo: can't find referenced class javax.persistence.Table Warning: com.package.Bar: can't find referenced class org.apache.commons.codec.binary.Hex

After that I wrote text above, did some tests and now I can run assembleRelease with success by changing the gradle file to use: 'com.android.tools.build:gradle:2.1.3' (was 2.2.0) 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' (was 1.5.0) And: apply from: 'https://raw.githubusercontent.com/adwiv/android-fat-aar/4308e779cd12b1398a67040d6ec6447c701bd0e2/fat-aar.gradle' (was master)

Do you have idea of the cause?

adwiv commented 7 years ago

The older script did not use an internal proguard, we simply remapped the R classes of embedded projects to point to the library R file.

The 2.2 gradle created an issue by stripping any class named R and inner classes from the generated aar archive which the internal proguard tries to fix. The proguard wants to resolve all classes although it doesn't use them actually. Hence the error.

The javax.persistence.Table is not a part of android java library, hence the warning. From what I understand, this class belongs to java enterprise edition and one of the included jars has a reference to it. Same way, the script is not able to find the commons-codec library in the dependencies. How are you including it?

If you can share the names or dependencies of your embedded projects, I would try to replicate the issue.

adwiv commented 7 years ago

Hi, Added the option to specify your own dontwarn options in file named fataar-rules.pro which is created automatically first time you run the script. Please check if it works as required.

williamlopes-dev commented 7 years ago

fataar-rules.pro is like a common proguard configuration file? Because some java classes were obfuscated together with proguard process.

adwiv commented 7 years ago

Yes.. it's included as a config file.. The obfuscation should not happen since we have the dontobsfucate option. Can you check the generated config file to see what configuration is applied. It's in the same location as mapping file.

On 07-Oct-2016 8:07 PM, "williamlopes-dev" notifications@github.com wrote:

fataar-rules.pro is like a common proguard configuration file? Because some java classes were obfuscated together with proguard process.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/adwiv/android-fat-aar/issues/33#issuecomment-252269523, or mute the thread https://github.com/notifications/unsubscribe-auth/AKfnZ8ESUqupzFLGL4_rDAkx02TrMDB2ks5qxlkYgaJpZM4KLWNo .

williamlopes-dev commented 7 years ago

When I tested my integration class has been obfuscated. I remember of add keep 'class foo.Bar' command to work correctly. I can compile without 'keep' command, but I can't use my library in that way.

Next week I must be able to test, after that, I'll back and tell if worked.

By the way, thank you so much my brother!!

adwiv commented 7 years ago

In another thread, another method has been suggested which will remove the need for internal proguard. I am hopeful it will get us out of the mess I have created by using proguard internally 🙂