標籤:receive depend jar sof img xml檔案 set filter compile
1.把要匯入成Mudle的項目修改成符合Library的格式
修改該項目中bulid.gradle檔案中第一行代碼
把
apply plugin: ‘com.android.application‘
修改為
apply plugin: ‘com.android.library‘
然後,修改AndroidManifiest.xml檔案中配置資訊,此處主要是把原來配置的項目Style等配置以及MainActivity配置刪除,這樣處理是為了防止重複。以下以一個我的Moudle檔案的AndroidManifiest.xml代碼作為對照(PS:如果以下程式碼範例不好對照,此處具體刪除資訊可以網上找其他相關文章參考):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.loonggg.lib.alarmmanager.clock"> <uses-permission android:name="android.permission.VIBRATE"/> <application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" > <receiver android:name="com.loonggg.lib.alarmmanager.clock.LoongggAlarmReceiver"> <intent-filter> <action android:name="com.loonggg.alarm.clock"/> </intent-filter> </receiver> <activity android:name=".ClockAlarmActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" ></activity> </application></manifest>
2.在要匯入Mudule項目中的gradle檔案中添加以下配置資訊2.1設定項目app目錄中build.gradle檔案資訊
dependencies { compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2‘, { exclude group: ‘com.android.support‘, module: ‘support-annotations‘ }) compile project(‘:mudle-name‘) compile ‘com.android.support:appcompat-v7:26.+‘ compile ‘com.android.support.constraint:constraint-layout:1.0.2‘ compile ‘com.android.support:design:26.+‘ compile ‘com.android.support:support-v4:26.+‘ testCompile ‘junit:junit:4.12‘}
關鍵一行:
compile project(‘:mudle-name‘) //mudle-name即要匯入成Mudle檔案的項目名稱
2.2緊接著設定項目根目錄中setting.gradle檔案資訊
在setting.gradle檔案中,添加新配置的Module的項目名,具體如下:
未改變之前代碼:
include ‘:app‘
改變之後:
include ‘:app‘, ‘:your module name‘
AndroidStudio中匯入module(簡單版)