Normally in android I can just edit the build.gradle file and place my compile dependencies like this:
dependencies {
compile 'com.android.support:support-v4:23.+'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-base:8.3.0'
}
How can I add a compile dependency in a codenameone project?
The generated project utilizes the jcenter() repository.
In order to add a compile dependency you will need to use the 'gradleDependencies' build hint, for example:
gradleDependencies=" compile 'com.facebook.android:facebook-android-sdk:4.7.0'\n"
Related
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
i'm trying to add compile method to build.gradle but i get this problem
i have android studio 3.5.2
and 5.4.1 gradle
You can replace compile with implementation:
implementation 'com.android.support:appcompat-v7:24.1.1'
implementation 'com.android.support:design:24.1.1'
But you are putting your dependencies in your build.gradle module Project. Place them in build.gradle module app.
I would like to create my own library .aar library file, and add it to different projects as a dependency in gradle. Also, how can I add *.aar library with own gradle file in local repository?
If you are planning to release the lib, it will be better not to include the dependent libraries in the packaged aar and instead add the same compile dependencies found in lib build script inside the build script of the app as such:
app build.gradle:
dependencies {
compile ':my-lib'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.14.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.google.android.gms:play-services:11.0.4'
}
That way users of your library won't face merging conflicts when they use public libraries like your library does, gradle will automatically resolve them.
If you are looking looking for a better way to include all dependencies in a single library: Don't. Gradle cannot resolve merging conflicts if a aar contains a certain lib packaged inside while the app as well depends on the lib and contains code calling methods from lib
You can read more details here: Exclude jar-library from aar
And here Generate AAR file with all dependencies
So, I guess you should move your .aar file to lib directory in the project folder (create it if necessary). After that in your build.gradle file in dependency section write like that
dependencies {
...
implementation(name: 'your-library-name', ext: 'aar')
...
}
I am trying to add a subproject to my main one in Android Studio. I have it compiling in the build gradle of the whole project. When ever I try to build the project or compile it it gives me out this error.
Error:(9, 0) Could not find method compile() for arguments [project ':subProject.exude'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
Here is the code for the build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
compile project('subProject.exude')
I think this can be a solution to your problem. Let's say there are two modules in your project, typically named as app and lib. Now you want to use lib module in your app module. So, you need to add it to your build.gradle(app module).
compile project(':lib')
I have it compiling in the build gradle of the whole project.
It may imply two cases:
You're adding compile project('subProject.exude') to your root/project build.gradle
You're adding compile project('subProject.exude') to all of your module build.gradle
In first case, you must not add the compile project to your root build.gradle. Because it not belong there.
In second case, you're incorrectly adding the classpath to your dependencies block in your module build.gradle. This is incorrect, because you're adding classpath for dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
compile project('subProject.exude')
...
}
This is corrrect:
dependencies {
compile project('subProject.exude')
...
}
Module dependencies should not exist in root/project build.gradle.
In my project I am using SlidingUpPanel.
Due to a feature that I needed, I cloned the project to my machine and manipulated the library. I tested my feature on its demo project and everything is okay based on this project.
Now, I want to compile its library module in order to get .aar file and add it to my project. What I did is:
I opened cmd and navigated to root folder of slidingUpPanel project.
Ran this command: ./gradlew :library:build
Library compiled and created .aar under /library/build/outputs/aar/library-debug.aar
I copy/pasted this file into /libs folder of my project and updated build.gradle like this:
dependencies {
compile ANDROID_SUPPORT
compile CRASHLYTICS
compile 'com.facebook.android:facebook-android-sdk:3.20.0'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0.1'
compile 'com.android.support:recyclerview-v7:+'
// Local libs not in Maven Central
compile files('src/main/libs/httpclientandroidlib-1.2.1.jar')
compile files('src/main/libs/nineoldandroids-2.4.0.jar')
compile files('src/main/libs/niftynotification-1.2.jar')
compile files('src/main/libs/zendesk-1.0.0.1.jar')
compile files('src/main/libs/library-debug.aar')
}
After I sync gradle file, I'm getting error which is because SlidingUpPanelLayout does not recognise.
Any idea why the library cannot be recognised? Any idea would be appreciated. Thanks.
So, first, lets add this kind of repository in our build.gradle file.
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
Here, I assume that your aar files will be stored in the libs folder in your project.
You can now add a dependency like
dependencies {
compile 'net.my.package:mylib:1.0#aar'
}
In my project I use some local dependencies:
dependencies {
compile files('lib/mylib.jar')
}
Why when I call gradle dependencies I can't see this library as a dependency? Command gradle dependencies --configuration compile returns this:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
No dependencies
Dependencies downloaded from repository (maven/ivy) are visible. For example:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:14.0.1'
}
will show:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
\--- com.google.guava:guava:14.0.1
BUILD SUCCESSFUL
I should also add that dependencies are not shown but project compiles properly.
Gradle documentation on file dependency explains
File dependencies are not included in the published dependency descriptor for your project. However, file dependencies are included in transitive project dependencies within the same build. This means they cannot be used outside the current build, but they can be used with the same build.
Use api(name: 'mylib', ext: 'jar') as a workaround.