Android Gradle实现项目(';:项目名称';)不工作
我在Android Studio 3.5中有一个项目,我正试图使用实现项目(“:data”)在Gradle中添加一个模块,但它不起作用 我在“数据”模块下导入了改型和Okhttp3,但它一直说“无法解决符号改型”。这意味着它找不到导入 这是一个以前可以工作的老项目,但当我在AndroidStudio 3.5中打开它时,它就开始遇到这个问题 以下是我的应用程序升级代码:Android Gradle实现项目(';:项目名称';)不工作,android,gradle,Android,Gradle,我在Android Studio 3.5中有一个项目,我正试图使用实现项目(“:data”)在Gradle中添加一个模块,但它不起作用 我在“数据”模块下导入了改型和Okhttp3,但它一直说“无法解决符号改型”。这意味着它找不到导入 这是一个以前可以工作的老项目,但当我在AndroidStudio 3.5中打开它时,它就开始遇到这个问题 以下是我的应用程序升级代码: // app Gradle apply plugin: 'com.android.application' android
// app Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.assign"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
supportlib = '26.0.0'
constraintlay = '1.0.2'
annotations = '27.0.2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Support lib
implementation "com.android.support:appcompat-v7:$supportlib"
implementation "com.android.support:design:$supportlib"
implementation "com.android.support:support-v4:$supportlib"
implementation "com.android.support:support-annotations:$annotations"
implementation "com.android.support.constraint:constraint-layout:$constraintlay"
implementation project(':data')
}
// data Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
cruncherEnabled = false
}
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
ext {
retrofit = '2.4.0'
okhttp3 = '3.11.0'
gson = '2.8.1'
annotations = '27.0.2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:support-annotations:$annotations"
// Network
implementation "com.google.code.gson:gson:$gson"
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.squareup.okhttp3:okhttp:$okhttp3"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
}
以下是我的数据分级代码:
// app Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.assign"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
supportlib = '26.0.0'
constraintlay = '1.0.2'
annotations = '27.0.2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Support lib
implementation "com.android.support:appcompat-v7:$supportlib"
implementation "com.android.support:design:$supportlib"
implementation "com.android.support:support-v4:$supportlib"
implementation "com.android.support:support-annotations:$annotations"
implementation "com.android.support.constraint:constraint-layout:$constraintlay"
implementation project(':data')
}
// data Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
cruncherEnabled = false
}
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
ext {
retrofit = '2.4.0'
okhttp3 = '3.11.0'
gson = '2.8.1'
annotations = '27.0.2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:support-annotations:$annotations"
// Network
implementation "com.google.code.gson:gson:$gson"
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.squareup.okhttp3:okhttp:$okhttp3"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
}
尝试更改第三方库的
api项目(':data')
或api
api“com.squareup.okhttp3:okhttp:$okhttp3”
...
说明:
api
与旧的compile
相同。它支持传递依赖。
而实现
是直接依赖的
例如,如果您使用implementation
在应用程序中添加依赖项
实施项目(':data')
在这种情况下,您只能访问数据
模块文件。因此,它会给出错误信息
有关更多详细信息,请查看
快乐编码
谢谢尝试更改第三方库的api项目(':data')
或api
api“com.squareup.okhttp3:okhttp:$okhttp3”
...
说明:
api
与旧的compile
相同。它支持传递依赖。
而实现
是直接依赖的
例如,如果您使用implementation
在应用程序中添加依赖项
实施项目(':data')
在这种情况下,您只能访问数据
模块文件。因此,它会给出错误信息
有关更多详细信息,请查看
快乐编码
谢谢谢谢,但这并不能解决我的问题。我最终在两个模块上导入了相同的库,至少这暂时解决了问题,直到我得到一个有效的解决方案。谢谢,但这并不能解决我的问题。我最终在两个模块上导入了相同的库,至少这暂时解决了问题,直到我得到一个有效的解决方案。