简体   繁体   English

在Android Studio中使用口味和-错误,错误的AndroidManifest已选择/未合并

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

I am trying to set up flavours, so I can build different apps in he same project that share the same code... But I am not sure I am doing it fully correct... 我正在尝试设置风味,因此我可以在他的项目中构建共享相同代码的不同应用...但是我不确定我是否完全正确...

I have created a project called com.sharedid.app in folder W:\\android-studio-projects\\sharedid\\ 我在文件夹W:\\ android-studio-projects \\ sharedid \\中创建了一个名为com.sharedid.app的项目。

For this I have 为此,我有

1) Created AndroidManifest.xml in W:\\android-studio-projects\\sharedid\\app\\src\\main looking like this: 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) In W:\\android-studio-projects\\sharedid\\app\\src\\main\\java ... I have all .java files 2)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ main \\ java ...我拥有所有.java文件

3) In W:\\android-studio-projects\\sharedid\\app\\src\\main\\res I have all shared and/or dummy resources 3)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ main \\ res中,我拥有所有共享和/或虚拟资源

For my flavour I have: 对于我的口味,我有:

1) I have created AndroidManifest.xml in W:\\android-studio-projects\\sharedid\\app\\src\\myflavour (this file is what defines everything - it is unqiue for each flavour) 1)我在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor中创建了AndroidManifest.xml(此文件定义了所有内容-每种风味都不统一)

2) In W:\\android-studio-projects\\sharedid\\app\\src\\myflavour\\res I have a single folder drawable-hdpi conttaining variois graphics 2)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor \\ res中,我有一个包含可绘制图形的可绘制的hdpi文件夹

3) In W:\\android-studio-projects\\sharedid\\app\\src\\myflavour\\assets I have all sorts of data, configuration and graphic files for that specifc app. 3)在W:\\ android-studio-projects \\ sharedid \\ app \\ src \\ myflavor \\ assets中,我具有特定应用程序的各种数据,配置和图形文件。 (read by the code at runtime) (在运行时由代码读取)

4) In *W:\\android-studio-projects\\sharedid\\app\\src\\myfavlour* I have the following AndroidManifest.xml file: 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>

Here's how "Gradle Scripts" - "Build Gradle" (Module: app) looks like: 这是“ 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'
}

My problem is this 我的问题是

When I in "build variants" select "module=app" and "build-variant=com.myflavour.appDebug" and click "Run > Debug..." I get a dialog that states: "Error: Default activity not found" 当我在“构建变体”中选择“ module = app”和“ build-variant = com.myflavour.appDebug”,然后单击“运行>调试...”时,出现一个对话框,指出: “错误:未找到默认活动”

From my studies of flavours I should not need to define sourcesets paths since I use the default conventenion of files for flavours... If I am right abnout that - then why does it not see the Androidmanifest file for the flavour selected? 从我对风味的研究中,我不需要定义源集路径,因为我使用风味的默认文件约定 ...如果我不正确,那么为什么为什么看不到所选风味的Androidmanifest文件?

Links for reference I base my understanding on: 参考链接我的理解基于:

Additional troubleshooting 其他疑难解答

In my attempt to find the root of this problem, I begun to suspect manifest merging was not working. 在试图找出问题根源的过程中,我开始怀疑清单合并无法正常工作。 The reason for this suspicion was that if I ignored the error about no activity and tried to push the compiled app out on the mobile, I would get a warning about the version number being smaller than the one installed on the mobile - clear indication wrong manifest file was being used. 引起怀疑的原因是,如果我忽略了有关无活动的错误并尝试将已编译的应用程序推出移动版,则会收到有关版本号小于移动版上安装的版本的警告-明确指示错误的清单文件正在使用中。

So i have also tried to delete src/main/AndroidManifest.xml which results in error: 所以我也试图删除src / main / AndroidManifest.xml导致错误:

A problem was found with the configuration of task ':app:checkmyflavourDebugManifest'. 发现任务':app:checkmyflavourDebugManifest'的配置存在问题。 File W:\\android-studio-projects\\sharedid\\src\\main\\AndroidManifest.xml' specified for property 'manifest' does not exist 为属性“清单”指定的文件W:\\ android-studio-projects \\ sharedid \\ src \\ main \\ AndroidManifest.xml'不存在

This leads me to believe Android Studio is completely ignoring that I am actually specifying it to use another manifest file... And the same time though it would seem i an building the correct variation build. 这使我相信Android Studio完全忽略了我实际上是在指定它使用另一个清单文件...同时,尽管看起来我正在构建正确的版本。

I would apreciate any comment/analysis on this - even if just to confirm my thinking of the cause 我希望对此发表任何评论/分析-即使只是为了确认我对原因的看法

Screenshot of my current setup 我当前设置的屏幕截图

(in this screenshot I have experiemented deleting main/shared androidmanifest file, but otherwise it complete) (在此屏幕截图中,我曾尝试删除主要/共享的androidmanifest文件,但否则已完成)

Latest update 最新更新

I conclude flavors is not working / my gradle setup must be wrong. 我得出结论说口味不起作用/我的gradle设置一定是错误的。 If I eg select building variation myflavourDebug Android studio does not use the manifest file defined in gradle. 例如,如果我选择建筑物变体,则myflavourDebug Android Studio不使用gradle中定义的清单文件。 This alone should be enough to conclude where the problem relies. 仅此一项就足以得出问题根源所在。

Maybe my gradle file is wrong somehow, I don't know, but I have taken great care in getting i right. 我不知道也许我的gradle文件是错误的,但是我已经非常注意要正确。 If someone posts an asnwer while bounty is active I will try hurry and assign it. 如果有人在赏金有效期间发布了一个请求,我将尝试快点进行分配。

I think the problem is here: 我认为问题出在这里:

applicationId "com.myflavour.app"

You define your applicationIs as com.myflavour.app in your build.gradle. 您可以在定义applicationIs为com.myflavour.app在你的build.gradle。 In your AndroidManifest, you specifiy 在您的AndroidManifest中,您可以指定

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

as your main Activity. 作为您的主要活动。 Your main activity should be named after your applicationId, if I'm not wrong. 如果我没记错的话,您的主要活动应以applicationId命名。 So basically, you should try to change either your manifest to state your activity as com.myflavour.app and arrange your packaging accordingly, or you could just use the same applicationId for your flavour. 因此,基本上,您应该尝试更改清单以将您的活动声明为com.myflavour.app并相应地安排您的包装,或者您可以只使用相同的applicationId作为风味。

to use Flavours It's not required to create Manifest files for every of them. 使用风味剂不需要为每个风味剂创建清单文件。 Just put all your classes in src/mani/AndroidManifest.xml file. 只需将所有类放在src / mani / AndroidManifest.xml文件中。 If you still wish to use both files remove conflicts by not overriding "intent-filter" block: 如果仍然希望同时使用这两个文件,请通过不覆盖“ intent-filter”块来消除冲突:

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

Use it only once. 只能使用一次。

And finally, you can find a lot useful information on http://developer.android.com/tools/building/manifest-merge.html 最后,您可以在http://developer.android.com/tools/building/manifest-merge.html上找到很多有用的信息

Fast quote from there: 从那里快速报价:

During the build process, the manifest merge process stores a record of each merge transaction in the manifest-merger--report.txt file in the module build/outputs/logs folder. 在构建过程中,清单合并过程将每个合并事务的记录存储在模块build / outputs / logs文件夹中的manifest-merger--report.txt文件中。 A different log file is generated for each of the module's build variants. 为每个模块的构建版本生成一个不同的日志文件。

It's not possible to merge manifests with different package names. 无法合并具有不同包名称的清单。
I think this is the problem. 我认为这是问题所在。
Just remove package="com.myflavour.app" from myflavour manifest. 只需从myflavor清单中删除package="com.myflavour.app"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM