Import module in Android studio (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 build.gradle file in this project

hold

apply plugin: 'com.android.application'

Change to

apply plugin: 'com.android.library'

Then, modify the configuration information in the androidmanifest.xml file. This is mainly to delete the original configuration of project Style and MainActivity configuration, so as to prevent duplication. Here is a comparison with the Android manifest.xml code of my cloud file (PS: if the following code examples are not easy to compare, please refer to other relevant articles for specific deletion information on the Internet):

<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 in the Mudule project to be imported

2.1 information of build.gradle file in app directory of configuration 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 is the name of the project to be imported into the Mudle file

 

2.2 next to the setting.gradle file information in the root directory of the configuration project

In the setting.gradle file, add the project name of the newly configured Module as follows:

Previous code unchanged:

include ':app'

After change:

include ':app', ':your module name'

Tags: Android Gradle xml Junit

Posted on Sun, 03 May 2020 04:37:42 -0400 by sebastiaandraaisma