簡體   English   中英

在Android Studio中使用口味和-錯誤,錯誤的AndroidManifest已選擇/未合並

[英]Using flavours in Android studio and - error with wrong AndroidManifest selected / not merged

我正在嘗試設置風味,因此我可以在他的項目中構建共享相同代碼的不同應用...但是我不確定我是否完全正確...

我在文件夾W:\\ android-studio-projects \\ sharedid \\中創建了一個名為com.sharedid.app的項目。

為此,我有

1)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ main中創建AndroidManifest.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.sharedid.app"
  android:versionCode="1"
  android:versionName="1.0"
>
<activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>  
</manifest>

2)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ main \\ java ...我擁有所有.java文件

3)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ main \\ res中,我擁有所有共享和/或虛擬資源

對於我的口味,我有:

1)我在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor中創建了AndroidManifest.xml(此文件定義了所有內容-每種風味都不統一)

2)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor \\ res中,我有一個包含可繪制圖形的可繪制的hdpi文件夾

3)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor \\ assets中,我具有特定應用程序的各種數據,配置和圖形文件。 (在運行時由代碼讀取)

4)在* W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myfavlour *中,我具有以下AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.myflavour.app"
  android:versionCode="2"
  android:versionName="2.0"
>
<uses-sdk
  android:minSdkVersion="9"
  android:targetSdkVersion="17" 
/>
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
  android:allowBackup="true"
  android:icon="@drawable/app_logo__forlarge"
  android:label="@string/MicAppName"
  android:theme="@style/MicTheme_myflavour"
  android:name="com.shared.app.MicApp"
>
<provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="com.myflavour.app.fileprovider"
  android:grantUriPermissions="true"
  android:exported="false">
  <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_filepaths" />
</provider>
<activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>        
<activity>...more...</activity>        
</application>
</manifest>

這是“ Gradle Scripts”-“ Build Gradle”(模塊:app)的樣子:

apply plugin: 'com.android.application'

android {
    signingConfigs {
    }
    compileSdkVersion 21
    buildToolsVersion '21.1.2'
    defaultConfig {
        applicationId "com.sharedid.app"
        minSdkVersion 9
        targetSdkVersion 17
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }
    repositories {
        maven { url "https://jitpack.io" }
    }     
    productFlavors {
      myflavour {
          applicationId "com.myflavour.app"
      }
    }
    sourceSets {
      main {
        manifest.srcFile 'src/main/AndroidManifest.xml'
      }
      myflavour {
        manifest.srcFile 'src/myflavour/AndroidManifest.xml'
      }
    }           
}    
dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:appcompat-v7:21.1.2'
    compile 'com.github.PhilJay:MPAndroidChart:v2.0.8'
}

我的問題是

當我在“構建變體”中選擇“ module = app”和“ build-variant = com.myflavour.appDebug”,然后單擊“運行>調試...”時,出現一個對話框,指出: “錯誤:未找到默認活動”

從我對風味的研究中,我不需要定義源集路徑,因為我使用風味的默認文件約定 ...如果我不正確,那么為什么為什么看不到所選風味的Androidmanifest文件?

參考鏈接我的理解基於:

其他疑難解答

在試圖找出問題根源的過程中,我開始懷疑清單合並無法正常工作。 引起懷疑的原因是,如果我忽略了有關無活動的錯誤並嘗試將已編譯的應用程序推出移動版,則會收到有關版本號小於移動版上安裝的版本的警告-明確指示錯誤的清單文件正在使用中。

所以我也試圖刪除src / main / AndroidManifest.xml導致錯誤:

發現任務':app:checkmyflavourDebugManifest'的配置存在問題。 為屬性“清單”指定的文件W:\\ android-studio-projects \\ sharedid \\ src \\ main \\ AndroidManifest.xml'不存在

這使我相信Android Studio完全忽略了我實際上是在指定它使用另一個清單文件...同時,盡管看起來我正在構建正確的版本。

我希望對此發表任何評論/分析-即使只是為了確認我對原因的看法

我當前設置的屏幕截圖

(在此屏幕截圖中,我曾嘗試刪除主要/共享的androidmanifest文件,但否則已完成)

最新更新

我得出結論說口味不起作用/我的gradle設置一定是錯誤的。 例如,如果我選擇建築物變體,則myflavourDebug Android Studio不使用gradle中定義的清單文件。 僅此一項就足以得出問題根源所在。

我不知道也許我的gradle文件是錯誤的,但是我已經非常注意要正確。 如果有人在賞金有效期間發布了一個請求,我將嘗試快點進行分配。

我認為問題出在這里:

applicationId "com.myflavour.app"

您可以在定義applicationIs為com.myflavour.app在你的build.gradle。 在您的AndroidManifest中,您可以指定

<activity android:name="com.shared.app.SharedMain"
    android:label="@string/MicMainName" >

作為您的主要活動。 如果我沒記錯的話,您的主要活動應以applicationId命名。 因此,基本上,您應該嘗試更改清單以將您的活動聲明為com.myflavour.app並相應地安排您的包裝,或者您可以只使用相同的applicationId作為風味。

使用風味劑不需要為每個風味劑創建清單文件。 只需將所有類放在src / mani / AndroidManifest.xml文件中。 如果仍然希望同時使用這兩個文件,請通過不覆蓋“ intent-filter”塊來消除沖突:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

只能使用一次。

最后,您可以在http://developer.android.com/tools/building/manifest-merge.html上找到很多有用的信息

從那里快速報價:

在構建過程中,清單合並過程將每個合並事務的記錄存儲在模塊build / outputs / logs文件夾中的manifest-merger--report.txt文件中。 為每個模塊的構建版本生成一個不同的日志文件。

無法合並具有不同包名稱的清單。
我認為這是問題所在。
只需從myflavor清單中刪除package="com.myflavour.app"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM