0

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).

Dast6Tino
  • 67
  • 8
  • 1
    Do you mean that the app module contains a `android:name=”App”`, which would override a feature module’s `android:name=”AppFeat”` when it is an installed app? – TWL Sep 06 '17 at 22:02
  • @TWL Yes, normal application is work, but instant work only debug version( – Dast6Tino Sep 07 '17 at 10:41

2 Answers2

5

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.

TWL
  • 6,228
  • 29
  • 65
  • I have a combination of Kotlin/Dagger2. So, I need to call Android injector from App class for all my activities. I tried tools:replace way, but I still never see my App.onCreate() being called from the debugger. I looked at isInstantApp(), but it looks like meant for use within an Activity. Are you sure that it is called for you? – andude Sep 19 '17 at 22:14
  • Yes, I have tested `InstantApps.isInstantApp()` in an Application implementation. It works for me. – TWL Sep 20 '17 at 00:06
-1

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>
MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65