evi*_*evi 12 android android-gradle-plugin
我是gradle的新手,我有一个依赖性的问题.我有以下项目结构:
-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar
Run Code Online (Sandbox Code Playgroud)
无论MyAppPro和MyAppFree依靠MyAppLibrary,这就要看ThirdPartyLibraryWrapper.顾名思义,它ThirdPartyLibraryWrapper是外部库的包装器,即ThirdPartyLibrary.aar.
这是我的配置:
build.gradle MyAppPro
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':MyAppLibrary')
}
Run Code Online (Sandbox Code Playgroud)
build.gradle MyAppLibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}
Run Code Online (Sandbox Code Playgroud)
build.gradle ThirdPartyLibraryWrapper
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
}
Run Code Online (Sandbox Code Playgroud)
当gradle sync完成时,我遇到了这个错误:
MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄清问题在哪里?
top*_*hyr 33
其他项目看到该:ThirdPartyLibraryWrapper项目依赖于一个名为的工件ThirdPartyLibrary-0.1.0:aar.Java(和Android)库不会将它们自己的依赖项捆绑在一起 - 相反,它们只是发布它们的依赖项列表.消费项目则加载它不仅直接取决于库负责,但所有的图书馆是图书馆依赖.
这样做的净效果:MyAppFree是加载:ThirdPartyLibraryWrapper,然后看到它:ThirdPartyLibraryWrapper依赖于ThirdPartyLibrary-0.1.0:aar,因此也试图加载它.但是,:MyAppFree不知道ThirdPartyLibrary-0.1.0:aar生活在哪里......所以它失败了.
解决方案是repositories在所有其他项目中放置类似的块.试试这个:
repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}
Run Code Online (Sandbox Code Playgroud)
使用该project(...).file(...)方法将使您无需硬编码路径,而是使用Gradle DSL通过查找项目并让它动态地执行分辨率来解析文件系统路径.
| 归档时间: |
|
| 查看次数: |
9288 次 |
| 最近记录: |