Separate manifest for instant app

1.1k views Asked by At

Can I use different manifests for instant app and a regular application?
In more detail, I need to specify different classes "App" in the "android:name=App" field (application tag).

2

There are 2 answers

2
TWL On BEST ANSWER

There are a few ways to do this:

If you must have two different manifests, then you will need to use tools:replace, example:

Your installed-app module’s manifest:

<application
    android:name="com.example.App"
    tools:replace="android:name"/>

Your feature module’s manifest:

<application
    android:name="com.example.feature.AppFeat">

When your installed-app is built, it will run with App, and when your instant-app is built, it will run with AppFeat. You can play with variations of this.

But it would be easier if you use isInstantApp() to branch off, in just one Application implementation.

1
MαπμQμαπkγVπ.0 On

To help you start with, here is a sample code from github about instant apps. You can check the structure of the code below:

<!--
  ~ Copyright 2017 Google Inc.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.google.android.instantapps.samples.hello.feature">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
            android:allowBackup="true"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"
            android:supportsRtl="true">

        <activity
                android:name=".HelloActivity"
                android:label="@string/title_activity_hello">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter
                    android:autoVerify="true"
                    android:order="1">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="https" />
                <data android:scheme="http" />
                <data android:host="hello.instantappsample.com" />
                <data android:pathPrefix="/hello" />
            </intent-filter>
            <meta-data
                    android:name="default-url"
                    android:value="https://hello.instantappsample.com/hello" />
        </activity>
        <activity
                android:name=".GoodbyeActivity"
                android:label="@string/title_activity_goodbye">
            <intent-filter
                    android:autoVerify="true"
                    android:order="2">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="https" />
                <data android:scheme="http" />
                <data android:host="hello.instantappsample.com" />
                <data android:pathPrefix="/goodbye" />
            </intent-filter>
        </activity>

    </application>
</manifest>

Here is the Manifest file structure to help you further in your build stage.

The code snippet below shows the general structure of the manifest file and every element that it can contain. Each element, along with all of its attributes, is fully documented in a separate file.

<?xml version="1.0" encoding="utf-8"?>

<manifest>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>