使用时,摇篮上编译命令行的Android库项目不能导入另一个库项目的R舱 [英] Android Library project can't import R class of another library project when using gradle to compile on command line
问题描述
我有这样的结构,我的Android项目:
I have this structure for my android project:
ProjectDir
settings.gradle
MyApp(depends on LibraryA and LibraryB)
-->build.gradle
-->All the other android code
LibraryA (depends on LibraryB)
-->build.gradle
-->All the other android code
LibraryB (Has lots of resources that are used in LibraryA and MyApp)
-->build.gradle
-->All the other android code
我可以编译Android应用程序就好了使用Eclipse和Android的工作室。 LibraryA的进口LibraryB的R档做进口com.LibraryB.R;
我还利用 com.LibraryB.R.layout的。 ...
键入code参考只要我在IDE的东西都很好。
I can compile the android app just fine using both eclipse and Android Studio. LibraryA imports the R file of LibraryB by doing " import com.LibraryB.R;
" I also make use of com.LibraryB.R.layout....
type references in code and as long as I'm in the IDE things are fine.
我想获得的东西来构建我们的CI服务器的命令行,我已经试过Ant和摇篮,我最终得到了相同的生成错误只。
I am trying to get things to build from the command line for our CI server and I have tried both ant and gradle and I end up getting the same build error in each.
LibraryA/example.java:10:error:cannot find symbol import com.LibraryB.R
我甚至去发布LibraryB作为本地AAR文件,并用它来建立LibraryA的程度
I have even gone to the extent of publishing LibraryB as a local aar file and using it to build LibraryA
LibraryB build.gradle
LibraryB build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
group = 'com.libraryb'
version = '1.0'
apply plugin: 'android-library'
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
}
}
}
task install(dependsOn: uploadArchives)
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
LibraryA的build.gradle
LibraryA build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.libraryb:LibraryB:1.0'
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
MyApp的build.gradle
MyApp build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
group = 'com.myapp'
version = '1.0'
apply plugin: 'android-library'
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
}
}
}
task install(dependsOn: uploadArchives)
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':LibraryA')
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
settings.gradle
settings.gradle
include ':MyApp'
include ':LibraryA'
我需要能够从其他库项目和主要的应用程序访问LibraryB的资源。我似乎无法找出什么我做错了。任何帮助将是巨大的。据透露,从Eclipse中使用生成的摇篮剧本给了同样的问题。
I need to be able to access the resources of LibraryB from other library projects and the main app. I can't seem to figure out what I'm doing wrong. Any help would be great. Fyi, using the generated gradle scripts from eclipse give the same issue.
推荐答案
您好:我有同样的问题,我的Android库项目,使用另一个库(actionBarSherlock)。它不能解决进口com.actionbarsherlock.R; 当我在gradle.build改了行: 应用插件:机器人库 至: 应用插件:'机器人' 那么顺利。
Hello I had same problem, my android library project, uses another library (actionBarSherlock). It can't resolve import com.actionbarsherlock.R; when I changed the line in gradle.build: apply plugin: 'android-library' to: apply plugin: 'android' then it goes well.
但我需要它有这样一个图书馆。
But I needed it have like a library.
这里的解决方案: 解决办法是,从包括库R上的文件生成到库中。 而不是进口com.actionbarsherlock.R; 采用进口com.myprojectalsolibrary.R;
SOLUTION HERE: Solution Is that R files from included library are generated to your library. instead import com.actionbarsherlock.R; use import com.myprojectalsolibrary.R;
这篇关于使用时,摇篮上编译命令行的Android库项目不能导入另一个库项目的R舱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!