Solvek
Solvek

Reputation: 5370

Manifest merging in Android Studio

Is there any way to use ADT's manifest merging feature (manifestmerger.enabled=true in project.properties) in Android Studio?

Upvotes: 2

Views: 1469

Answers (1)

Hun
Hun

Reputation: 3798

1. create sample project

enter image description here

2. add new module

enter image description here

enter image description here

enter image description here

3. Module Setting

enter image description here

enter image description here

enter image description here

4. Remove files in App Module

Move app/~~~/values/style.xml to common/~~~/values/style.xml

enter image description here

enter image description here

edit 1.

<!-- app/~~~/AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kr.mymy.manifestmergerforandroidstudio" >
 
    <application >
        <activity
            android:name="kr.mymy.common.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

edit 2.

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">  <!-- add this line -->
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

edit 3.

package kr.mymy.common;
 
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
 
public class MainActivity extends ActionBarActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
   
   
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        int id = item.getItemId();
     
        if (id == R.id.action_settings)
        {
            Toast.makeText(getApplicationContext(), "test toast", Toast.LENGTH_LONG).show();
        }
     
        return super.onOptionsItemSelected(item);
    }
}

enter image description here

Upvotes: 1

Related Questions