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> ...

Google Map v2 signed map isssue fixed

Hi Step 1: Develop Map Application  using android studio Step 2: For Map viewing we need to have google api key .in order to get api key we need to register application in google api console  https://console.developers.google.com/apis/ Step 3; For getting SHA1 Key please follow the steps            1) Go the java installed folder location , open cmd                 Eg: C:\Program Files\Java\jdk1.7.0_04\bin            2)  Type                   Windows keytool -list -v -keystore "CHANGE WITH OUR KEYSTORE LOC" -alias ALIASNAME -storepass PASSWORD -keypass PASSWORD                   Mac & Linux  keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android Ref:  http://www.truiton.com/2015/04/obtaining-sha1...

Store Image to Google Cloud Store using Google App engine java

Here is sample code for uploading image files to cloud storage bucket in google cloud platform Step 1 Create a google cloud project in cloud (https://console.cloud.google.com/)  enable cloud storage Step 2: Create a new web application project I am using Eclipse with Java for App engine Project Step 3: create a POST web service method the below code for upload image to the existing bucket in google cloud and the uploaded image url will be returned Code   @Path("/addres")  @POST       @Consumes(MediaType.MULTIPART_FORM_DATA)    public String addRestaurant( @FormDataParam("imgname")  String imagename,            @FormDataParam("file") InputStream uploadedInputStream,         @FormDataParam("file") FormDataContentDisposition restImages     ) throws IOException  {   try { // Create your service object Storage storage = St...