2013-07-30 25 views
12

私の会社のプロジェクトをMavenからGradleに移行しようとしていますが、これまではすべてのPOMを対応するbuild.gradleファイルに変換できましたが、建物のサブモジュールに兄弟サブモジュールのリソース、Gradleプロジェクト

- Core-UI 
---- Utils 
---- FieldPanels 

サブモジュールFieldPanelは、Utilsで定義されている色やその他のリソースを使用します。私は依存関係として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のは

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' 
} 
+0

のソースです、あなたのbuild.gradleファイルを投稿することができますか? – buzeeg

+0

はい、申し訳ありませんが、早くそれをしたはずです。 –

+0

それはいいようです。あなたは2つのプロジェクトをsetting.gradleファイルに含めましたか? – buzeeg

答えて

2

をgradle.buildあなたsettings.gradleを含めることができます。コンパイルの依存関係に不正なパスがあるのだろうかと思います。 「:common.android.utilsを」ここ

あなたはfieldPanelsからの依存関係がこれが意味することはutilsのライブラリモジュールはGradleのために知られなければならないということである

compile project(":common.android.utils") 

utilsのように宣言している方法です。代わりにこれが代わりになるはずですか?

compile project(":Core-UI:Utils") 
+0

私はライブラリプロジェクトをセットアップしていますが、問題はライブラリプロジェクト間で共有されるリソースによって異なります。 2つの図書館プロジェクトがあると想像してください。LAとLBとLBはLAに依存しています。 LAのLBのリソースを参照すると、R.id.whateverが見つからないと言ってコンパイルが失敗します。 (だから、通常のJavaコードを参照するだけで正常に動作します...) – Jeroen

+0

@jtietemaあなたがしたいことを言うことはできませんできません。 LAのコンパイルタスクがLBのリソース生成フェーズに依存する明示的なタスク依存関係を作成することを検討しましたか?あなたのソースがコンパイルされる前に 'R'クラスが生成されます。なぜなら、そのようなものがうまくいかない理由はわかりません。 – dcow

+0

@DavidCowdenすべてのものJavaは正常に動作します。私の問題はリソースIDに固有です。私はアプリケーションプロジェクトからのみライブラリリソースIDを参照でき、他のライブラリプロジェクトからは参照できないようです。私はこれがリソースIDが一定ではなく、コンパイル後に変更されることと関係があると考えています。 – Jeroen

0

あなたはAndroidのメーカー/ IDEAでこの問題の建物に実行している場合は、プロジェクト設定で、あなたのライブラリモジュールにlibraryチェックボックスをチェックすることを忘れないでください。

また、別のバージョンのアンドロイドプラグイン、0.8+などを使用してみてください。 もう1つ考えました。アンドロイドプラグインと7つのJavaで異なる問題がありましたが、使用すると6つを試してみてください。

1

「2つのライブラリプロジェクトLAとLBと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> 

のは、私たちが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> 
関連する問題