使用gradle构建多项目时遇到一些问题.我读了所有类似的问题但没有任何帮助.我的项目结构如下:
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 …不存在”.这个包在app模块中使用,但它可以在App / libraries / Core / Core / src / main / java中找到.你可以帮帮我吗?
解决方法
如果您使用Core作为库,则应更改apply plugin:’android’以应用插件:’android-library’在App / libraries / Core / Core / build.gradle中