多项目gradle生成错误:包不存在

使用gradle构build多项目时遇到一些问题。 我读了所有类似的问题,但没有任何帮助 我的项目结构如下所示:

App/ settings.gradle app/ build.gradle libraries/ Core(git submodule)/ Core/ build.gradle libraries/ ZBarLibrary/ build.gradle settings.gradle 

应用/ 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') 

应用程序/应用/的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') } 

应用程序/库/核心/核心/的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 } } 

应用程序/库/核心/库/ 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'] } } } 

在App目录下命令“gradle build”会产生错误:“package com … does not exist”。 这个包在应用程序模块中使用,但它可以在App / libraries / Core / Core / src / main / java中find。 你可以帮帮我吗?

如果你使用Core作为库,你应该改变apply plugin: 'android'来在App / libraries / Core / Core / build.gradle中 apply plugin: 'android-library'

你的应用程序模块的build.gradle应该包含(除其他外)

 apply plugin: 'com.android.application' dependencies { compile project(':my_library_module') } 

你的库模块的build.gradle文件应该包含

 apply plugin: 'com.android.library' 

为了解决包没有find错误,在我添加的app模块的build.gradle文件

 dependencies { // ... compile project(':library') } 

它将library模块添加为app模块的依赖项