AndroidStudio中匯入module(簡單版)

來源:互聯網
上載者:User

標籤: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(簡單版)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.