2013-07-30 14 views
12

Tôi đang cố gắng di chuyển dự án của công ty mình từ Maven sang Gradle, cho đến nay tôi đã có thể chuyển đổi tất cả POM thành các tệp build.gradle tương ứng, nhưng tôi đã gặp một vấn đề trong mô-đun phụ khi xây dựng.Tài nguyên về mô-đun phụ anh chị em, dự án Gradle

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

Mô-đun phụ FieldPanel sử dụng màu sắc và các tài nguyên khác được xác định trong Utils. Tôi đã thử thêm dự án Utils như một phụ thuộc, nhưng nó không hoạt động, tôi đang thiếu gì?

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

bạn có thể gửi file build.gradle của bạn? – buzeeg

+0

Có, xin lỗi, nên làm điều đó sớm hơn. –

+0

Điều đó có vẻ ổn. Bạn đã bao gồm hai dự án trong tệp setting.gradle chưa? – buzeeg

Trả lời

2

Bạn có thể bao gồm settings.gradle của bạn. Tôi tự hỏi nếu bạn có một con đường không chính xác trong phụ thuộc biên dịch của bạn.

Đây là cách bạn đã tuyên bố sự phụ thuộc từ fieldPanels để utils

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

Điều này có nghĩa là các mô-đun utils thư viện phải được biết đến gradle ": common.android.utils". Có lẽ nó nên được thay thế này?

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

Tôi đã thiết lập các dự án thư viện và hoạt động, nhưng vấn đề là cụ thể với tài nguyên được chia sẻ giữa các dự án thư viện. Hãy tưởng tượng bạn có 2 dự án thư viện LA và LB và LB phụ thuộc vào LA. Nếu tôi tham khảo một tài nguyên trong LB là từ LA, biên dịch sẽ thất bại, nói rằng nó không thể tìm thấy R.id.whatever. (Vì vậy, tham khảo mã Java bình thường hoạt động tốt ...) – Jeroen

+0

@jtietema không nói những gì bạn muốn làm không thể được thực hiện. Bạn đã khám phá việc tạo ra một phụ thuộc nhiệm vụ rõ ràng trong đó các nhiệm vụ biên dịch trong LA phụ thuộc vào giai đoạn tạo tài nguyên của LB và ngược lại? Lớp 'R' được tạo ra trước khi nguồn của bạn được biên dịch vì vậy tôi không thấy lý do tại sao một cái gì đó như thế sẽ không hoạt động. – dcow

+0

@DavidCowden tất cả mọi thứ Java làm việc tốt. Vấn đề của tôi là cụ thể với id tài nguyên. Có vẻ như tôi chỉ có thể tham khảo các id tài nguyên thư viện từ một dự án ứng dụng chứ không phải từ các dự án thư viện khác. Tôi nghi ngờ điều này có một cái gì đó để làm với id tài nguyên không được liên tục, nhưng thay đổi sau khi biên dịch. – Jeroen

0

Nếu bạn đang chạy vào tòa nhà vấn đề này trong Android Studio/IDEA, đừng quên kiểm tra hộp kiểm library trên module thư viện của bạn trong các thiết lập dự án.

Ngoài ra, hãy thử sử dụng một phiên bản plugin android khác, ví dụ 0.8+. Và một ý nghĩ khác: có và vẫn có thể là các vấn đề khác nhau với plugin android và 7 java, nếu bạn sử dụng nó, hãy thử sử dụng 6.

1

Lấy ví dụ về "2 dự án thư viện LA và LB và LB phụ thuộc vào LA "đây là một vài ví dụ làm việc.

Hãy nói rằng LA có file strings.xml sau

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="la_resource">la resource</string> 
</resources> 

Hãy nói rằng LB có file strings.xml sau

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="lb_resource">lb resource</string> 
</resources> 

Hãy nói rằng chúng ta muốn xác định một giao diện tùy chỉnh tên TestView trong LB. TestView sẽ tham chiếu la_resource từ LA và lb_resource từ LB. Đây là nguồn cho 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)); 
    } 
} 

Giả sử chúng tôi muốn xác định một chế độ xem tùy chỉnh khác có tên TestView2 trong LB. TestView2 sẽ thổi phồng một bố cục XML. Bố cục XML sẽ tham chiếu la_resource từ LA và lb_resource từ LB. Đây là nguồn gốc cho 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); 
    } 
} 

Và đây là nguồn gốc cho 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> 
Các vấn đề liên quan