我正在尝试将我公司的项目从Maven迁移到Gradle,到目前为止,我已经能够将所有POMs转换成相应的build.gradle文件,但是在构建时,我在子模块中遇到了一个问题。
- Core-UI
---- Utils
---- FieldPanels子模块FieldPanel使用Util中定义的颜色和其他资源。我尝试将Utils项目添加为依赖项,但是它没有工作,我缺少什么?
/home/development/AndroidStudioProjects/com.project/core-ui/common.android.fieldpanels/build/bundles/debug/res/layout/base_summary_step_layout.xml:2: error: Error: No resource found that matches the given name (at 'background' with value '@color/wizard_summary_bg').Utils gradle.build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.2'
}
}
apply plugin: 'android-library'
android {
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
res {
srcDirs = [
'res'
]
}
}
}
compileSdkVersion 15
buildToolsVersion '17.0'
dependencies {
compile group: 'com.company.ipos.android', name: 'commons.pos.micropos.api', version: '0.0.35-SNAPSHOT'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.5'
}
}
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
url repoUrl
}
maven {
credentials {
username mavenUser
password mavenPassword
}
url libsReleasesUrl
}
maven {
credentials {
username mavenUser
password mavenPassword
}
url libsSnapshotsUrl
}
}fieldPanels gradle.build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.2'
}
}
apply plugin: 'android-library'
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
url repoUrl
}
maven {
credentials {
username mavenUser
password mavenPassword
}
url libsReleasesUrl
}
maven {
credentials {
username mavenUser
password mavenPassword
}
url libsSnapshotsUrl
}
}
android {
dependencies {
compile group: 'com.company.ipos.android', name: 'commons.pos.micropos.api', version: '0.0.35-SNAPSHOT'
//compile group: 'com.company.ipos.android', name: 'common.android.utils', version: '0.0.35-SNAPSHOT'
compile project(":common.android.utils")
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.5'
}
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
res {
srcDirs = [
'res',
]
}
}
}
compileSdkVersion 15
buildToolsVersion '17.0'
}发布于 2014-02-27 19:20:53
你能包括你的settings.gradle吗?我想知道在编译依赖项中是否有不正确的路径。
下面是如何声明从fieldPanels到utils的依赖关系
compile project(":common.android.utils")这意味着必须知道utils库模块可以分级":common.android.utils“。也许应该是这样?
compile project(":Core-UI:Utils")发布于 2014-03-06 07:12:29
以您的“2个库项目LA和LB依赖于LA”为例,这里有几个工作示例。
假设LA有以下strings.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="la_resource">la resource</string>
</resources>假设LB有以下strings.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="lb_resource">lb resource</string>
</resources>假设我们想在LB中定义一个名为TestView的自定义视图。TestView将引用LA的la_resource和LB的lb_resource。以下是TestView的源代码
package com.example.myapplication3.lb;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class TestView extends TextView {
public TestView(Context context) {
super(context);
setText(context.getString(R.string.la_resource) + " " + context.getString(R.string.lb_resource));
}
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
setText(context.getString(R.string.la_resource) + " " + context.getString(R.string.lb_resource));
}
public TestView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setText(context.getString(R.string.la_resource) + " " + context.getString(R.string.lb_resource));
}
}假设我们希望在LB中定义另一个名为TestView2的自定义视图。TestView2将膨胀XML布局。XML布局将引用LA的la_resource和LB的lb_resource。以下是TestView2的源代码
package com.example.myapplication3.lb;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.TextView;
import org.w3c.dom.Text;
public class TestView2 extends FrameLayout {
public TestView2(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.test_view_2, this);
}
public TestView2(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.test_view_2, this);
}
public TestView2(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInflater.from(context).inflate(R.layout.test_view_2, this);
}
}这是test_view_2.xml的来源
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/la_resource"
android:padding="4dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lb_resource" />
</LinearLayout>发布于 2014-03-04 07:23:19
如果在Android /IDEA中遇到此问题,请不要忘记在项目设置中选中库模块上的library复选框。
此外,尝试使用不同版本的安卓插件,例如0.8+。还有一个想法: android插件和7 java存在不同的问题,如果你使用它,试着使用6。
https://stackoverflow.com/questions/17954790
复制相似问题