Import module in AndroidStudio (simple version ),
1. Modify the project to be imported into Mudle to conform to the Library format.
Modify the first line of code in the bulid. gradle file of this project
Set
apply plugin: 'com.android.application'
Change
apply plugin: 'com.android.library'
Then, modify the configuration information in the AndroidManifiest. xml file. Here, we mainly Delete the configuration such as the previously configured project Style and MainActivity configuration to prevent duplication. The following uses the AndroidManifiest. xml code of my Moudle file as the reference code (PS: if the following code examples are difficult to compare, you can refer to other related articles for specific deletion information here ):
<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. Add the following configuration information to the gradle file of the Mudule project to be imported. 2.1 configure the build. gradle file information in the app directory of the project.
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'}
Key line:
Compile project (': mudle-name') // mudle-name indicates the name of the project to be imported into the Mudle file.
2.2 configure the setting. gradle file in the root directory of the project.
In the setting. gradle file, add the project name of the newly configured Module as follows:
Code before modification:
include ':app'
After the change:
include ':app', ':your module name'