Skip to main content

Multiple apk based on Flavours in Android Studio



Step 1. Create Android Studio Project

Step 2. Go to the build.gradle file in the app module then add Flavours in that file

productFlavors {

    demo {
        applicationIdSuffix ".demo"
        resValue "string", "app_name", "Demo App"
    }
    full {
        applicationIdSuffix ".full"
        resValue "string", "app_name", "Full App"    }
}

after changes sync gradle ,their will be option Build Variants their we can switch demo / full application build

 Full Source code of build.gradle




apply plugin: 'com.android.application'
android {
    compileSdkVersion 25   
    buildToolsVersion "25.0.2"
    defaultConfig {
//        applicationId "com.example.nithin.flavoursample"        
//       minSdkVersion 14        
//       targetSdkVersion 25   
//       versionCode 1  
//       versionName "1.0"
//        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
   }
    buildTypes {
        release {
            minifyEnabled false      
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'      
            }
    }


    productFlavors {

        demo {
            applicationIdSuffix ".demo"
            resValue "string", "app_name", "Demo App"
        }
        full {
            applicationIdSuffix ".full"
            resValue "string", "app_name", "Full App"        }
    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'    })
    compile 'com.android.support:appcompat-v7:25.1.0'   
     compile 'com.android.support:design:25.1.0'    
     testCompile 'junit:junit:4.12'}




Step 3. Create folders (demo/full) under src



Step 4. Create java,res, manifest file folders
          before adding files change build variants option

full application (build variant - fullDebug)



demo application  (build variant - demoDebug)



 Manifest 

Manifest file (main)


<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.nithin.flavoursample">

   

</manifest>




Manifest file (demo)


<manifest xmlns:android="http://schemas.android.com/apk/res/android"    >

    <application        
         android:allowBackup="true"        
         android:icon="@mipmap/ic_launcher"        
         android:label="@string/app_name"        
         android:supportsRtl="true"        
         android:theme="@style/AppTheme">
        
        <activity            
            android:name="com.example.nithin.flavoursample.demo.Login"            
            android:label="@string/app_name"            
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Manifest file (full)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    >


<application   
   android:allowBackup="true"   
   android:icon="@mipmap/ic_launcher"    
   android:label="@string/app_name"    
   android:supportsRtl="true"    
   android:theme="@style/AppTheme">
    <activity        
        android:name="com.example.nithin.flavoursample.full.Login"        
        android:label="@string/app_name"        
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>


Login Page
Login Page (demo)

package com.example.nithin.flavoursample.demo;

public class Login extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

    }

}
Login Page (full)

package com.example.nithin.flavoursample.full;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.nithin.flavoursample.R;

/** * Created by nithin on 1/11/2017. */
public class Login extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

    }

}




Change the build variants according for the build

to take full version build change variant option then application will be build accordingly
to take demoversion build change variant option then application will be build accordingly


The file will be complied and manifest file will be merged and deployed

Comments

Popular posts from this blog

Bluetooth Chat Example

Manifest File <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="com.example.android.BluetoothChat"       android:versionCode="1"       android:versionName="1.0">     <uses-sdk minSdkVersion="7" />     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />     <uses-permission android:name="android.permission.BLUETOOTH" />     <application android:label="@string/app_name"                  android:icon="@drawable/app_icon" >         <activity android:name=".BluetoothChat"                   android:label="@string/app_name"                   android:configChanges="orientation|keyboardHidden">             <intent-filter> ...

Custom TextView With Images in Android

Create a custom XML Tag with image and text 1) Class extends Textview import java . util . regex . Matcher ; import java . util . regex . Pattern ; import android . content . Context ; import android . text . Spannable ; import android . text . style . ImageSpan ; import android . util . AttributeSet ; import android . util . Log ; import android . widget . TextView ; public class TextViewWithImages extends TextView { public TextViewWithImages ( Context context , AttributeSet attrs , int defStyle ) { super ( context , attrs , defStyle ); } public TextViewWithImages ( Context context , AttributeSet attrs ) { super ( context , attrs ); } public TextViewWithImages ( Context context ) { super ( context ); } @Override public void setText ( CharSequence text , BufferType type ) { Spannable s = getTextWithImages ( getContext (), text ); super . setText...

AcceleroMeter Sensors with SurfaceMovements on Canvas

MainActivity.java import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class MainActivity extends Activity implements SensorEventListener { float x, y, sensorX, sensorY; Bitmap ball; SensorManager sm; Sensor s; MyBringBackSurface ourSurfaceView; /**  * Canvas Movement  */ public class MyBringBackSurface extends SurfaceView implements Runnable {     SurfaceHolder ourHolder;     Thread ourThread = null;     boolean isRunning = false;     public MyBringBackSurface(Context context) {         super(context)...