简体   繁体   中英

re-use the androidmanifest.xml in library project in android studio

I am buiding an android application with two version one for free and the other for paid.

Since most of the UI,feature of the two version are the same, so I create a Android library project to hold the common components of the app including the common Activity , View , Layout , Resources and the AndroidManifest.xml .

The library project is named MapBase .

Then I create two moudles(android application) named MapForFree and MapForPaid .

The structure:

+MapProject

  +MapBase
    build.gradle
  +MapForFree
    build.gradle
  +MapForPaid
    build.gradle

  build.gradle(with empty content)
  settings.gradle(content==> include ':MapBase', ':MapForFree', ':MapForPaid')

The MapBase/build.gradle:

apply plugin: 'android-library'
.....
dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile 'com.android.support:support-v4:18.0.0'
    compile fileTree(dir: 'libs', include: '*.jar')
}

MapForFee/build.gradle:

...
apply plugin: 'android'
...

Now I want to the MapForFree and MapForPaid to refer to the MapBase module, but I meet two problems:

1 The refer manner.

Should I set the dependency in the build.gradle file or using android stuido itself?

2 The AndroidManifest.xml.

Since the MapForFree and MapForPaid module have the same AndroidManifest.xml, so I copy this file from MapBase .

However, the file declare some Activities defined in the MapBase module. How to resolve this?

I'm not sure about your first question. For your second question, MapForFree and MapForPaid should each have their own AndroidManifest.xml . Any components that need to be defined in the manifest that come from MapBase should be defined using the full package name of MapBase before the component name.

For example, if you have an Activity defined in MapBase called MapBaseActivity , and it is in package com.example.app , it should be listed in the manifests for both MapForFree and MapForPaid as:

<activity android:name="com.example.app.MapBaseActivity">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM