2014-09-01 60 views
0

我正在開發一個應用程序,我決定在三個項目中潛入代碼。Gradle使用共享庫結果生成多個菜單圖標

其中包含我想在所有應用程序中使用的通用代碼。其中一個包含我想在一些類似項目中使用的通用代碼,它取決於通用代碼。最後一個是依賴於第二個項目的特定於客戶的主應用程序。

在根目錄下創建一個settings.gradle文件中像這樣

include ':CommonLib',':RdsManager',':RdsCommonLib' 

在每個子目錄創建一個build.gradle文件的依賴性。請參閱下面的示例代碼。

apk得到正確編譯,但是當我安裝它在設備(Android 3.2)中時,我發現我的應用程序的三個圖標。

一個正確啓動主應用程序。一次崩潰,最後一次啓動測試活動。

如果我用eclipse創建apk,一切都很正常。

如何使用gradle解決此問題。我必須從庫項目中刪除Androidmanifest.xml文件嗎?

的配置的gradle

的snipets下面CommonLib/build.gradle

buildscript { 
repositories { 
    mavenCentral() 
} 
.... 
apply plugin: 'android-library' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-v4.jar') 
     compile 'com.android.support:support-v4:18.0.+' 

} 

RdsCommonLib/build.gradle

evaluationDependsOn(':CommonLib') 

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.10.+' 
    } 
} 
apply plugin: 'android-library' 

和finnaly在RdsManager

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.10.+' 
    } 
} 
apply plugin: 'android' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':RdsCommonLib') 
} 

回答

1

我是否必須從庫項目中刪除Androidmanifest.xml文件?

您可能必須在某處修改或刪除某些<activity>元素。

Gradle for Android將合併清單。如果庫項目中有一個<activity>的清單,那麼該活動將自動添加到使用該庫的任何應用程序的清單中。

在你的情況,你的圖書館有在他們<activity>元素,其中顯然你需要或者刪除清單的<intent-filter>(如果你想在活動中使用的應用程序,只要不與MAIN/LAUNCHER過濾器) ,或完全刪除<activity>元素。

documentation for the manifest merging process,儘管在Gradle for Android達到1.0後該鏈接可能會過時。

0

好的,謝謝刪除<intent filter>是解決方案。 Gradle構建配置是正確的。

謝謝。