【问题标题】:Separate manifest for instant app免安装应用的单独清单
【发布时间】:2017-09-04 20:32:51
【问题描述】:

我可以为免安装应用和常规应用使用不同的清单吗?
更详细地说,我需要在"android:name=App" 字段(应用程序标签)中指定不同的类“App”。

【问题讨论】:

  • 你的意思是应用模块包含一个android:name=”App”,当它是一个已安装的应用时,它会覆盖一个功能模块的android:name=”AppFeat”
  • @TWL 是的,正常的应用程序是可以工作的,但即时工作只有调试版本(

标签: android android-manifest android-instant-apps


【解决方案1】:

有几种方法可以做到这一点:

如果您必须有两个不同的清单,那么您将需要使用tools:replace,例如:

您已安装应用模块的清单:

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

您的功能模块的清单:

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

当您的安装应用程序构建时,它将使用App 运行,而当您的即时应用程序构建时,它将使用AppFeat 运行。你可以玩这个的变体。

但如果您使用isInstantApp() 进行分支,只在一个应用程序实现中会更容易。

【讨论】:

  • 我有 Kotlin/Dagger2 的组合。所以,我需要从 App 类调用 Android 注入器来处理我的所有活动。我尝试了 tools:replace 方式,但我仍然没有看到我的 App.onCreate() 被调试器调用。我查看了 isInstantApp(),但它看起来像是在 Activity 中使用的。你确定它是为你调用的吗?
  • 是的,我已经在应用程序实现中测试了InstantApps.isInstantApp()。它对我有用。
【解决方案2】:

为了帮助您入门,这里有一个来自 github 的关于即时应用程序的示例代码。您可以检查以下代码的结构:

<!--
  ~ 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>

这里是Manifest file structure,可帮助您进一步完成构建阶段。

下面的代码 sn -p 显示了清单的一般结构 文件及其可以包含的每个元素。每个元素,连同 它的所有属性都完整地记录在一个单独的文件中。

<?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>

【讨论】:

  • 谢谢,我知道结构,但这不是我问题的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多