2017-09-04 49 views
0

我可以爲即時應用程序和常規應用程序使用不同的清單嗎?
更詳細地說,我需要在"android:name=App"字段(應用程序標籤)中指定不同的類「App」。即時應用程序的單獨清單

+1

您的意思是應用程序模塊包含一個'android:name =「App」',當它是一個已安裝的應用程序時,它將覆蓋功能模塊的'android:name =「AppFeat」? – TWL

+0

@TWL是的,正常的應用程序是工作,但即時工作只有調試版本( – Dast6Tino

回答

2

有幾個方法可以做到這一點:

如果你必須有兩個不同的體現,那麼你將需要使用tools:replace,例如:

你的安裝,應用程序模塊的清單:

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

你的功能模塊的清單:

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

當您安裝的應用程序被構建時,它將以App運行,並且當您的即時應用程序被構建時,它將以AppFeat運行。你可以玩這個變化。

但是,如果您使用InstantApps.isInstantApp()來分支,只需一個應用程序實現,那將更容易。 https://developer.android.com/topic/instant-apps/reference.html#isinstantapp

+0

我有一個Kotlin/Dagger2的組合。我嘗試了一些工具:替換方式,但是我仍然看不到我的App.onCreate()被調試器調用,我看着isInstantApp(),但它看起來像是爲了使用在一個Activity中,你確定它被調用嗎? – andude

+0

是的,我已經在一個應用程序實現中測試了'InstantApps.isInstantApp()',它適用於我。 – TWL

1

爲了幫助您入門,以下是來自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幫助您進一步在構建階段。

以下代碼片段顯示清單 文件及其可包含的每個元素的一般結構。每個元素和 的所有屬性都完全記錄在一個單獨的文件中。

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

)謝謝,我知道結構,但這不是我的問題的答案 – Dast6Tino

相關問題