Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiproject gradle build error: package does not exist

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?

like image 463
piobab Avatar asked Sep 02 '13 12:09

piobab


People also ask

What is subproject in gradle?

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.

How do I add a project in build gradle?

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).


2 Answers

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'
like image 154
Paul Houghton Avatar answered Oct 06 '22 01:10

Paul Houghton


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

like image 40
shakalaca Avatar answered Oct 06 '22 00:10

shakalaca