I git clone a complete gradle project "CompleteGradleProjA" from github and include it into my local project as a submodule. By "complete gradle project" I mean that I can go into directory "CompleteGradleProjA" and issue command
cd CompleteGradleProjA && gradle build
to build it.
My directory structure looks like this,
MyProj
|---CompleteGradleProjA
| |---build.gradle
|
|---build.gradle
My question is: How can I call "CompleteGradleProjA/build.gradle" without changing anything of it from my root "build.gradle"?
The following root "build.gradle" config does not help.
apply plugin: 'java'
dependencies {
compile project(':CompleteGradleProjA')
}
I got error message
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':compileJava'.
> Could not determine the dependencies of task ':compileJava'.
"CompleteGradleProjA" is an android porject and "CompleteGradleProjA/build.gradle" looks like this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
CompleteGradleProjA/build.gradle
apply plugin: 'com.android.library'
// if your project isn't library then use this:
// apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0' // if needed
}
settings.gradle
include ':CompleteGradleProjA'
Use apply plugin: 'com.android.library' or apply plugin: 'com.android.application' instead of apply plugin: 'java'
To include a custom project as part of your gradle build, first ensure the submodule is already included within the project folder and accessible via your settings.gradle. i.e.
include ':app', ':your_project_name'
You then register the project as a dependency of another by using in your project's build.gradle:
dependencies {
compile project(path: ':your_project_name')
}
In newer versions compile has been deprecated. See here on what to use.
Related
I am trying to import an external library into my application, the library is FFmpeg. Here is a link to the module.
I add the library to my libs folder (after downloading it), then from File > New > Import module > select FFmpeg. Now within my apps build gradle I add the line
compile project(':FFmpeg')
Now when I try and sync the project I get this error:
Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found.
When I open the file, this is the affected line
apply plugin: 'com.github.dcendents.android-maven'
Basically my end goal is to get the above lib into my project as an external library so I can modify the source code to fix some bugs within the library.
Any help is much appreciated, I have been trying to fix this problem for a really long time but I am not too good with Gradle besides just using dependencies.
Update 1
Apply problems are now fixed however it cant find variables like version name and rootProject.ext.compileSdkVersion as Integer
Error:(6, 0) Could not get unknown property 'VERSION_NAME' for project ':FFmpegAndroid' of type org.gradle.api.Project.
You need to add the plugin to your classpath root build.gradle. You can found it in the Gradle Android Maven plugin. Something like this:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// This is the classpath for the plugin
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
allprojects {
repositories {
jcenter()
}
}
UPDATED:
You should look at the ffmpeg android gradle.properties and add it to your root project, here it is:
VERSION_NAME=0.3.2
VERSION_CODE=28
GROUP=com.writingminds
POM_DESCRIPTION=Java implementation of ffmpeg for Android
POM_URL=https://github.com/writingminds/ffmpeg-android-java
POM_SCM_URL=https://github.com/writingminds/ffmpeg-android-java.git
POM_SCM_CONNECTION=scm:https://github.com/writingminds/ffmpeg-android-java.git
POM_SCM_DEV_CONNECTION=scm:https://github.com/writingminds/ffmpeg-android-java.git
POM_LICENCE_NAME=GNU GPLv3
POM_LICENCE_URL=https://github.com/writingminds/ffmpeg-android-java/blob/master/LICENSE.GPLv3
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=hiteshsondhi88
POM_DEVELOPER_NAME=Hitesh Sondhi
The VERSION_NAME is needed in the Ffmpeg Android build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"
// This is the library version used when deploying the artifact
version = VERSION_NAME
...
ADVICE:
It's better if you run the ffmpeg-android-java as independent project and then configure it so it can be installed to local maven. Read the details at my answer https://stackoverflow.com/a/46330142/4758255
You have to add the plugin in your buildscript block. You can add in the top-level build.gradle file or in your module/build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
//..current plugins
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
About the variables not found you have to check the build.gradle in the library on github
You have to define in your project these variables. Of course use your values.
ext {
compileSdkVersion = 22
buildToolsVersion = '22.0.1'
targetSdkVersion = 22
minSdkVersion = 16
versionCode = 28
versionName = "0.3.2"
}
i want to add
https://github.com/gabrielemariotti/cardslib
but android studio give me this error :
Error:(9, 0) Cause: cannot get property 'compileSdkVersion' on extra properties extension as it does not exist
The best way to use this library with Andriod Studio is to add this dependency in your build.gradle
dependencies {
compile 'com.github.gabrielemariotti.cards:library:1.9.1'
}
If you want to clone locally you should check the top level build.gradle (in the root) inside the github repo.
It sets some variables, and you have to add these parts in your top level build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
}
}
ext {
compileSdkVersion = 19
buildToolsVersion = "20.0.0"
}
I had same problem with ChangeLog Library.(https://github.com/gabrielemariotti/changeloglib)
I thought there is no need for applying android-sdk-manager plugin for a library, android library plugin is enough. So i removed android-sdk-manager plugin from build.gradle left only android library plugin like below.
Change this:
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
to this:
apply plugin: 'com.android.library'
It worked without any problem in my case. I hope it will help someone else too.
I'm trying to use RomainGuy's ViewServer (https://github.com/romainguy/ViewServer) with my Android Studio project using Gradle, and I can't get it to work.
My understanding is to add a folder in project root ('libraries'), drop the ViewServer directory into it (not the full ViewServer directory but the actual library viewserver folder within ViewServer, and reference it in settings.gradle
include ':VendorSearch'
include ':libraries:ViewServer'
and also in my build.gradle file
compile project(":libraries:ViewServer")
When I do this I get a message that says
Could not find any version that matches com.android.tools.build.gradle:0.5.+
I tried then manually updating build.gradle in ViewServer to use the latest build tools (0.7.+ at the time of posting), but I get the same error with the new gradle version.
Any help and general clarification of how to include non-jar third party libraries would be appreciated!
You probably need to add the repository. Change the gradle.build from:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
I am trying to make use of some maven dependencies in a new Android project, but I am new to using Android-Studio and Gradle. I looked at a few other solutions such as this:
How to import Maven dependency in Android Studio/IntelliJ?
and thought it looked simple enough. So I modified the build.gradle file to this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:android:4.1.1.4'
compile 'com.factual:factual-java-driver:1.7.7-android'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
but when I compiled the project I got the error:
Gradle: A problem occurred configuring root project 'LookAroundYouProject'.
> Failed to notify project evaluation listener.
> Main Manifest missing from /home/tstewart/AndroidStudioProjects/LookAroundYouProject/src/main/AndroidManifest.xml
I am not really sure what this is telling me. Currently it is just a simple hello world example and it worked before modifying the gradle file.
EDIT:
I moved the compile statements from the Top-level build file to the one within the application itself and for some reason this seemed to work and I no longer appear to be getting errors. Sadly I have no idea why this is the case.
I have a problem while building a project on Android using Gradle.
I have a project structure as following:
root
settings.gradle
build.gradle
- Project 1 (android studio "module")
build.gradle
- Project 2 (android studio "module")
build.gradle
If I select the project 1 and compile, it works
If I select the project 2 and compile, it works as well
Now, I would like to have a dependancy from the project 2 on the project 1 to reuse some of my application logic.
Following the doc I try to add in the project 2 build.gradle
dependencies {
compile project(':Project1')
}
but it doesn't work.
My settings.gradle contains:
include ':Project1', ':Project2'
You should apply the plugin android-library in your library project (project1) :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
}
Link to the Gradle documentation about making library projects.
If you want to reuse some logic from Project1 you should create a library project, Project3-lib. Move your reusable code to this new project and let Project1 and Project2 depend on it.
This is how you can do it:
settings.gradle
include ':Project3-lib', ':Project1', ':Project2'
In your Project1 and Project2 you add your new lib project
dependencies {
compile project(':Project3-lib')
}
In your top-level gradle.build file (so that you dont need it in all of your project build files)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
In your new Project3-lib project you have to apply the android-library plugin and not the android plugin
apply plugin: 'android-library'