3

I'm trying to have same activity name in different flavors, and install the right one for each flavor.

build.gradle :

android {
    ....
    buildscript {
        productFlavors {
            flavor1 {
                applicationId "com.example.MyApp.flavor1"
            }
            flavor2 {
                applicationId "com.example.MyApp.flavor2"
            }
            flavor3 {
                applicationId "com.example.MyApp.flavor3"
            }
        }
    }   
}

AndroidMAnifest.xml :

<activity
        android:name="${applicationId}.LaunchActivity"
        android:noHistory="false" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="*"
                android:path="*"
                android:scheme="@string/app_scheme_name" />
        </intent-filter>
...
<\activity> 

and every flavorX.java looks like this :

package com.example.MyApp.flavorX;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.example.MyApp.MainActivity;

public class LaunchActivity extends MainActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        String flavor = "~~~ flavorX ~~~~";
        Log.i("flavor", flavor);
        super.onCreate(savedInstanceState);
        Toast.makeText(this, flavor,Toast.LENGTH_SHORT).show();
    }
}

now...
for every flavor i run (with its build variant) by pressing the A.S. "green play button" these things happens:
1. build + compile ends successfully.
2. on the Run view tab i get this message :

    Installing com.example.MyApp.flavorX
    DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.MyApp.flavorX"
    pkg: /data/local/tmp/com.example.MyApp.flavorX
    Success
    Could not identify launch activity: Default Activity not found

3. the app is being installed on the device with the correct icon and name.
4. when pressing the icon that was just installed (=running from device) - everything is OK and the app acts just as requested - with it own flavor for each installation.

this is awful for debugging and fluent developing...
what should i do in order to be able to run each flavor with its variants through A.S??

thanks :)

4

2 回答 2

0

Every thing looks fine. Seeing your logs default activity couldn't be loaded which means you are forgetting to add Intent-Filter to your first activity that you have registered in the Android Manifest.xml.

         <activity
            android:name=".YourFirstActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.Main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
于 2016-07-27T15:44:30.680 回答
0

well, the issue is solved very easily.
in order to run each flavor from Android Studio directly i had to declare Specified Activity under Run -> Edit Configurations -> Android Application
this solution is required for every flavor that you want to run directly from Android Studio.

于 2016-08-16T07:18:24.457 回答