AndroidStudio中導入module(簡單版)


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'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM