I have some problems with building multiproject with gradle. I read all similar questions but nothing help. The structure of my projects looks like:
App/
settings.gradle
app/
build.gradle
libraries/
Core(git submodule)/
Core/
build.gradle
libraries/
ZBarLibrary/
build.gradle
settings.gradle
App/settings.gradle
include ':App', ':libraries:Core', ':libraries:ZBarLibrary'
project(':libraries:Core').projectDir = new File(settingsDir, 'libraries/Core/Core')
project(':libraries:ZBarLibrary').projectDir = new File(settingsDir, 'libraries/Core/libraries/ZBarLibrary')
App/app/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':libraries:Core')
}
App/libraries/Core/Core/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
instrumentTestCompile "junit:junit:4.5+"
compile project(':libraries:ZBarLibrary')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
App/libraries/Core/libraries/ZBarLibrary/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Command "gradle build" in App directory generates error: "package com… does not exist". This package is used in app module but it is find in App/libraries/Core/Core/src/main/java. Could you help me?
The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency. Example 2.
Open Android Studio and choose "Import project" and choose to use Gradle as the external model. Pick your settings. gradle file as the Gradle project. [Optional] Set your "Gradle home" folder (so the text turns black instead of gray).
Your app module's build.gradle should contain (among other things)
apply plugin: 'com.android.application'
dependencies {
compile project(':my_library_module')
}
Your library module's build.gradle file should contain
apply plugin: 'com.android.library'
If you're using Core as library you should change apply plugin: 'android'
to apply plugin: 'android-library'
in App/libraries/Core/Core/build.gradle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With