Provided Gradle Dependency Is AAR not JAR

落花浮王杯 提交于 2020-01-12 11:40:09

问题


I have an issue where I'm trying to include a library in my project called the ParseLoginUI.

The issue is it uses the provided tag instead of compile. I believe the provided tag means that the project needs to supply this dependency in order for the library to work rather than this library compiling the libraries itself.

So in my Android library it references the Facebook SDK like so.

 provided 'com.facebook.android:facebook-android-sdk:4.0.1'

Then in my mobile/build.gradle which is my main module I compile the Facebook sdks like so.

compile 'com.facebook.android:facebook-android-sdk:4.0.1'

I have been following the guide for installing this library and this is how you're meant to do it. Here is the warning I get that stops me from compiling thrown by the ParseLoginUI/build.gradle file (the one providing it).

Warning:Project ParseLoginUI: provided dependencies can only be jars. com.facebook.android:facebook-android-sdk:aar:4.0.1 is an Android Library.

The documentation for this library has a fix which is:

If you are using gradle 1.1.0 or above, you may encounter "Warning:Project ParseLoginUI: provided dependencies can only be jars. com.facebook.android:facebook-android-sdk:aar:4.0.1 is an Android Library". It is an open issue of android gradle build tool. Currently the workround is using gradle 1.0.0.

Fair enough but I don't want to downgrade my gradle (currently running v1.2.3) just to solve this issue. There must be a way round this or a better way of doing it.

My Question

How can I include the Facebook SDK in both the library module and my main module?


回答1:


you have already mentioned that it is an open issue in Gradle. If you are using ParseLoginUI as library module. Just change the build.gradle file in ParseLoginUI itself.

    provided 'com.facebook.android:facebook-android-sdk:4.0.1'
                              to
    compile 'com.facebook.android:facebook-android-sdk:4.0.1'



回答2:


Try this: http://www.labouisse.com/how-to/2014/07/28/gradle-provided-scope-and-intellij/

He basically mimics the provided implementation.




回答3:


According to this issue, it should be possible to do with Gradle plugin 1.3.0-beta3. You might need to update your build tools to version 23.0.0 rc1 or above.




回答4:


After try and error, I found the solution…

First of all, AAR means android archive library, which is not a JAR. I searched something called facebook-android-sdk-4.0.1.jar, but no luck.

The trick is download facebook code and add it as a module. Doing that, works perfectly and you can use gradle 1.2.3 with ParseLoginUI.

Go here: https://developers.facebook.com/docs/android/downloads

Download: https://developers.facebook.com/resources/facebook-android-sdk-4.0.1.zip Decompress it.

Go to your own project. -Remove in your ParseLoginUI gradle the reference to Parse

Press FILE, NEW, IMPORT MODULE.

Select a folder called facebook that is inside the zip you uncompressed.

Call that module facebook-android-sdk-4.0.1.

Now add in your parseloginui a dependency to that module, using:

compile project(':facebook-android-sdk-4.0.1’)

You also have to copy a file from the zip you downloaded to the new module folder, the file is gradle.properties. The one that has:

ANDROID_BUILD_MIN_SDK_VERSION=9

ANDROID_BUILD_TARGET_SDK_VERSION=21

ANDROID_BUILD_TOOLS_VERSION=21.1.2

ANDROID_BUILD_SDK_VERSION=21

That’s all.

Press SYNCHRONIZE and cross your fingers.

I worked in my case after several hours playing with gradle and android studio. Let me know if you get it. If you have reference problems (I had), use FILE, PROJECT STRUCTURE to add the jar references to your modules properly. (I wrote them manually and it seems it was a mistake in my parse references, probably one path or symbol, don’t know. Do that using the user interface of android studio will fix the problem). BTW, you can use a version of parse in ParseLoginUI and another more recent in your project (I didn’t test that for facebook version).

This is what I have in my ParseLoginUI gradle file:

compile 'com.parse.bolts:bolts-android:1.2.0'

compile 'com.android.support:support-v4:22.0.0'

compile project(':facebook-android-sdk-4.0.1')

compile files('libs/Parse-1.9.1.jar')

compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')

And this is what I have in my app gradle:

compile 'com.google.android.gms:play-services:7.5.0'

compile project(':facebook-android-sdk-4.0.1')

compile 'com.parse.bolts:bolts-android:1.2.0'

compile files('libs/Parse-1.9.2/Parse-1.9.2.jar')

compile files('libs/Parse-1.9.2/ParseFacebookUtilsV4-1.9.2.jar')

compile project(':ParseLoginUI’)

Note: I use Gradle version 2.4 and android plugin version 1.2.3. Selct that in FILE, PROJECT STRUCTURE, PROJECT.

Good luck.




回答5:


You can try this syntax:

provided (name:"", ext:'aar')

Be sure your main build.gradle has the path or maven repo to the aar package you want provided.




回答6:


instead of that,

  1. Clone ParseLoginUI from here

  2. Import ParseLoginUI as a module and include these on gradle

    compile project(':ParseLoginUI')
    compile 'com.facebook.android:facebook-android-sdk:4.0.1'
    

Hope this helps




回答7:


I had this problem with calligraphy (github.com/chrisjenx/Calligraphy) and gradle 2.3.3 . I changed the repository from jcenter() to mavenCentral() and now it is ok!



来源:https://stackoverflow.com/questions/31076270/provided-gradle-dependency-is-aar-not-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!