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

Problem with resources Gradle 3.1. #40

Open LilianaB opened 8 years ago

LilianaB commented 8 years ago

Hi,

I am testing the library with 'com.android.tools.build:gradle:2.2.1' and Gradle 3.1. I created my fat aar containing an .aar library. But when I try to use my newly created fat .aar library I get an error on the resources.

adwiv commented 8 years ago

Hi, can you check if it works with Gradle 2.14.1?

Which library defines the polygonStrokeWidth and other attributes? Is it embedded too?

I tried but could not replicate the issue. Maybe if you can create a sample that fails, it would be helpful.

Cheers.

LilianaB commented 8 years ago

Hi

I'll try later.

The library that defines polygonStrokeWidth is called scanbot. Here are examples of the library usages https://github.com/doo/Scanbot-SDK-Examples

Cheers.

adwiv commented 8 years ago

I too notices issue with 3.1.

When I run the clean task, it gives me error about classes in compileReleaseJavaWithJavac.

However building the APK works fine and gives no errors.

Will investigate when I get time.

LilianaB commented 8 years ago

I just tested with Gradle 2.14.1. I managed to create the .aar file but when I want to use it, it doesn't find the classes.

adwiv commented 8 years ago

Are you embedding the scan library in the fat aar? Or just compiling it with it as dependency? If the latter, are you publishing that dependency along with the fat aar?

LilianaB commented 8 years ago

I declared the dependency as embedded in the gradle file

apply from: 'https://raw.githubusercontent.com/adwiv/android-fat-aar/master/fat-aar.gradle'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    embedded 'io.scanbot:sdk-package-1:1.19.0'
    compile 'com.android.support:support-v4:24.2.1'
    testCompile 'junit:junit:4.12'
}

Having this I simply run the command "assembleRelease" to generate the .aar file

adwiv commented 8 years ago

Just delete the build dir and run it again with 2.14. Maybe uptodate check is creating issue.

I Can't test right now myself but if you can create a simple fat aar project that shows this problem, it will be much easy to understand.

LilianaB commented 8 years ago

I have this public repo https://github.com/LilianaB/ScanApp The scanbotwrapper directory is the library that I want to pack with fat aar. I hope this works as an example.

adwiv commented 8 years ago

I tried the sample and it works for me with 2.14 in the android studio. It however does not find the classes if I set transitive dependencies to false - which looks like the same problem you are having.

Maybe you are not exporting the dependencies for the io.scanbot:sdk-package-1 in the pom file. So when you try to use your generated aar, the app can't find the io.scanbot:sdk-base:1.19.0 package on which the io.scanbot:sdk-package-1:1.19.0 depends.

One easy way would be to add it as compile after embedded

embedded 'io.scanbot:sdk-package-1:1.19.0'
compile 'io.scanbot:sdk-base:1.19.0'

However, if you want to totally embed sdk-base too, then you'll have to take a look at its dependencies listed here and see what all you want to embed and export list of remaining dependencies.

LilianaB commented 8 years ago

Hi,

I believe the pom is fine. Is your pom file similar to mine?

screen shot 2016-10-20 at 15 16 04

LilianaB commented 8 years ago

I declared the embedded dependency as follow.

    embedded ('io.scanbot:sdk-package-1:1.19.0') {
        transitive = true
    }
adwiv commented 8 years ago

Can you check the generated pom file? Does it define sdk-base as dependency?

Setting transitive true is not useful as it is the default. The embedded dependencies are not part of the pom. The sub dependencies of embedded dependencies need to be manually added to pom

There is a publish.gradle in the github which used to work. Not tested it for over 1 year. You can read it for some guidence and modify it for your needs.

LilianaB commented 8 years ago

The generated pom file is in my previous post, sdk-base is defined as a dependency.

I used the publish.gradle but I guess is not working because I am not able to see second level dependencies.

LilianaB commented 8 years ago

I believe it is not working for you either. To test it properly you have to create a separate project that uses the resulting scanbotwrapper.aar.

adwiv commented 8 years ago

Sorry I didn't see that comment with screenshot. Pom file looks good..

Are you publishing the aar file to maven and consuming from there?

Can you make it work if you include the dependency for sdk-base in the app you are building.?

LilianaB commented 7 years ago

It works if I include the reference to the private maven repository that contains the scanbot library (including sdk-base). That means if I add this:

        maven {
            url 'http://nexus.scanbot.io/nexus/content/repositories/releases/'
        }
        maven {
            url 'http://nexus.scanbot.io/nexus/content/repositories/snapshots/'
        }

I guess this means the fat aar does not contain the dependencies. It definitely knows what the dependencies are, thanks to the pom file. But it doesn't contain them because it requires the maven repo to solve them.

adwiv commented 7 years ago

You are right. But I imagined gradle sync should fail since it can't find the dependency and say that explicitly.

If you are planning to ship this as a library for third party users, you should ideally get the sdk-base and other scanbot dependencies published to maven central or jcenter.

Else you should embed sdk-base and any other scanbot dependencies in the tree into your aar file.

LilianaB commented 7 years ago

Indeed when I use the fat .aar library in an external project the gradle fails.

Any ideas on how to embed dependencies into the .aar file? I thought the fat-aar.gradle was for that.

adwiv commented 7 years ago

fat-aar.gradle will not embed sub dependencies, you have to manually declare them as embedded. In your case it will be like

embedded 'io.scanbot:sdk-package-1:1.19.0'
embedded 'io.scanbot:sdk-base:1.19.0'
embedded 'io.scanbot:detector:1.4.4'
embedded 'io.scanbot:licensing:1.3.1'

I tested that, but then it crashes with java.lang.NoClassDefFoundError: net.doo.snap.ScanbotSDKInitializer$a error although net.doo.snap.ScanbotSDKInitializer exists.

This is probably due to the warning messages received while compiling related to Ignored InnerClasses attribute. Scanbot seems to be stripping the InnerClass attribute during proguard when they built the sdk. And this is somehow messing up the dex when generated with fat-aar :(

LilianaB commented 7 years ago

Oh ok. Thanks for the help anyway.

adwiv commented 7 years ago

Right. It means gradle is not able to resolve the dependency. But I imagined it should fail the sync since it can't find the dependency.

If you are planning to ship this as a library for third party users, you should get the sdk-base and dependencies published to maven central or jcenter.

Else you should embed sdk-base and any other scanbot dependencies into your aar file.

On 21-Oct-2016 11:20 AM, "LilianaB" notifications@github.com wrote:

It works if I include the reference to the private maven repository that contains the scanbot library (including sdk-base). That means if I add this:

    maven {
        url 'http://nexus.scanbot.io/nexus/content/repositories/releases/'
    }
    maven {
        url 'http://nexus.scanbot.io/nexus/content/repositories/snapshots/'
    }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/adwiv/android-fat-aar/issues/40#issuecomment-255299449, or mute the thread https://github.com/notifications/unsubscribe-auth/AKfnZ-yqNQpakzROVlElrF5Gg-IyC_6yks5q2FKpgaJpZM4KYRzh .