Android Studio将本地项目添加到Gradle
我已经附上了我当前项目设置的屏幕截图,但是在从“library”项目获取代码以在“SampleApp”项目中工作时遇到了问题。My project build.gradle包含以下内容:Android Studio将本地项目添加到Gradle,gradle,android-studio,Gradle,Android Studio,我已经附上了我当前项目设置的屏幕截图,但是在从“library”项目获取代码以在“SampleApp”项目中工作时遇到了问题。My project build.gradle包含以下内容: buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } allprojec
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
include ':SampleApp'
include ':library'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 11
}
buildTypes {
release {
runProguard false
}
}
}
而my settings.gradle包含以下内容:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
include ':SampleApp'
include ':library'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 11
}
buildTypes {
release {
runProguard false
}
}
}
My SampleApp build.gradle包含以下内容:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
include ':SampleApp'
include ':library'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 11
}
buildTypes {
release {
runProguard false
}
}
}
my library build.gradle包含以下内容:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
include ':SampleApp'
include ':library'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 11
}
buildTypes {
release {
runProguard false
}
}
}
奇怪的是,如果我尝试在SampleApp项目中包含库项目中的一段代码,我可以添加相关的,使用AndroidStudio功能添加正确的导入,并且没有错误。然而,一旦我开始构建,就会出现一个错误,表明我的包不存在。我还进入了Android Studio项目属性,并添加了库作为SampleApp的依赖项。非常感谢您的帮助 在您的库的build.gradle中,而不是:
apply plugin: 'android'
这样做:
apply plugin: 'android-library'