Method for Importing module in Android Studio (Simple Version)
- 2021-08-12 03:36:55
- OfStack
1. Modify the project to be imported into Mudle to conform to Library
Modify line 1 of the bulid. gradle file in this project
Put
apply plugin: 'com.android.application'
Modify to
apply plugin: 'com.android.library'
Then, modify
AndroidManifiest.xml
File configuration information, here is mainly the original configuration of the project Style configuration and MainActivity configuration deleted, such processing is to prevent duplication. The following is a comparison with the AndroidManifiest. xml code of my Moudle file (PS: If the following code example is not easy to compare, the specific deletion information here can be found on the Internet for reference):
<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 that you want to import into the Mudule project
2.1 Configuration Project build. gradle File Information in app Directory
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 1:
compile project(':mudle-name') //mudle-name That is, to import into Mudle Project name of file
2.2 Configure the setting. gradle file information in the root directory of the project immediately
In the setting. gradle file, add the project name of the newly configured Module as follows:
Before changing the code:
include ':app'
After the change:
include ':app', ':your module name'
Summarize