I created 2 flavors (com.example.admin.deb) and (com.example.admin.lab_127) And the difference between this two packages is in the MainActivity.java file (just two lines of code). In the build.gradle I created
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.admin.deb"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors{
pro {
applicationId "com.example.admin.lab_127"
}
deb {
applicationId "com.example.admin.deb"
dependencies {
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'org.lucasr.dspec:dspec:0.1.1'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.+'
}
But when I change Build Variant nothing happens.My folder structure like this:
-app
----manifests
------------AndroidManifest.xml
----java
--------com.example.admin.deb
-----------MainActivity.java
--------com.example.admin.lab_127
-----------data
-----------ItemAdapter.java
-----------MainActivity.java
----res
So what I did wrong? Thanks in advance.
If you want to have a different version of the same class in the two flavor you'll need to create it in both flavors and do not put it in src/main/java. In your case:
src/deb/java/com/example/admin/deb/MainActivity.java
src/pro/java/com/example/admin/deb/MainActivity.java
You should implement next structure:
app
src
deb
java
com.example.admin.deb
MainActivity.java
main
java
com.example.admin.deb
res
pro
java
com.example.admin.deb
MainActivity.java
Related
I am trying to build Cocos2d-x 3.16 android-studio project by following http://cocos2d-x.org/docs/cocos2d-x/en/installation/Android-Studio.html.
But the gradle build of libcocos2dx module is giving this error -
Error:(14, 0) Could not find method bitwiseNegate() for arguments [] on source set main of type com.android.build.gradle.internal.api.DefaultAndroidSourceSet.
on line 14.0 of the following build.gradle file.-
apply plugin: 'com.android.library'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
~
sourceSets.main {
aidl.srcDir "../java/src"
java.srcDir "../java/src"
manifest.srcFile "AndroidManifest.xml"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: '../java/libs', include: ['*.jar'])
}
following is the gradle.properties
PROP_COMPILE_SDK_VERSION=26
PROP_MIN_SDK_VERSION=14
PROP_TARGET_SDK_VERSION=27
PROP_APP_PLATFORM=16
PROP_APP_ABI=x86
Did you just try to remove this extra ~ line 14 ?
This operator does not have its place here.
I'm building an application which needs a library with 2 variants - simulator & actual.
My objective is to create build tasks say assembleSimulatorDebug & assembleDebug.
assembleSimulatorDebug will include simulator module/library and assembleDebug will include actual module to build the apk.
I'm thinking of having if else blocks in dependencies sections of build.gradle. Can I have something like this?
I'm very new to gradle and trying from yesterday to set up something like this. It will be v helpful if anyone can provide some hints or links where I can get an idea to achieve this.
Update:
Found another solution. It's in another my answer.
It is possible by usage of 'Flavor products' of android gradle plugin. You can split library implementation by product flavor.
Initial requirements 'com.android.tools.build:gradle:1.0.0', Android Studio 1.0.1.
I created project at GitHub, so you'll be able to get it, run and learn.
You need to create two flavors of your app and library, too. For example, normal and simulator
Application's build.gradle
apply plugin: 'com.android.application'
android {
lintOptions {
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.tivogi.gradle"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
normal {
}
simulator {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
normalCompile project(path: ':library', configuration: 'normalRelease')
simulatorCompile project(path: ':library', configuration: 'simulatorRelease')
}
Library's build.gradle
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
normal {
}
simulator {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Library:
split implementation between flavors by productFlavors (see my sample project if will have questions about that);
add publishNonDefault true into its build.gradle
From Gradle Plugin User Guide
It is also possible to publish all variants of a library. We are planning to allow this while using a normal project-to-project dependency (like shown above), but this is not possible right now due to limitations in Gradle (we are working toward fixing those as well).
Publishing of all variants are not enabled by default.
To enable them:
android {
publishNonDefault true
}
Application:
add normal and simulator product flavors (productFlavors);
add next lines to dependencies section
normalCompile project(path: ':library', configuration: 'normalRelease')
simulatorCompile project(path: ':library', configuration: 'simulatorRelease')
From Gradle Plugin User Guide
To create a dependency on another published artifact, you need to specify which one to use:
dependencies {
flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}
After all of that you'll be able to build 2 variants of applicaiton: normal and simulator.
Found solution for 2 libraries, it looks simpler. It's based on next from official guide
Finally, like Build Types, Product Flavors can have their own dependencies. For instance, if the flavors are used to generate a ads-based app and a paid app, one of the flavors could have a dependency on an Ads SDK, while the other does not.
dependencies {
flavor1Compile "..."
}
So you can create 2 individual libraries and create 2 flavors, for example, libraries are library-normal and library-simulator and flavors are normal and simulator.
Application build.gradle
apply plugin: 'com.android.application'
android {
lintOptions {
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.tivogi.gradle"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
normal {
}
simulator {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
normalCompile project(":library-normal")
simulatorCompile project(":library-simulator")
}
Application:
add only those lines into dependencies;
normalCompile project(":library-normal")
simulatorCompile project(":library-simulator")
Library:
does not require any change;
I published sample project of this solution at individual-libraries branch.
I am running into the zero supported device issue when publishing an Android application. I upload an APK, and Google Play tells me there is zero supported device.
My manifest is pretty simple, the only thing apart from the <application> section is this:
<uses-permission android:name="android.permission.INTERNET" />
I have no file in app/libs. I am using Android Studio.
The build.gradle file looks like this:
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.the.application"
minSdkVersion 15
targetSdkVersion 20
versionCode 902
versionName "0.9.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
production {
packageName "com.the.application"
}
test {
packageName "com.the.application.test"
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.zxing:core:3.0.0'
compile 'com.google.zxing:android-integration:3.1.0'
}
Any clue what could cause that?
I am trying to learn android in android studio.Now i imported an eclipse project in android studio and now while trying to run it it is not building.Some problems in gradle may be..
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:support-v4:21.0.0-rc1
my build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.example.practise"
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:gridlayout-v7:+'
}
Can anyone help me to find out the problem??
Change your dependencies
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:gridlayout-v7:19.1.0'
}
Using the +, you are getting the last release.
Currently the last release is the compile 'com.android.support:support-v4:21 and it has a minSdk='L' because it is a preview release.
Use it only to test the android 'L' preview.
Try editing the following line to your Android Manifest file, like so:
dependencies {
compile 'com.android.support:support-v4:21+'
}
Then your project should build.
Change your dependencies in app/build.gradle to lower version
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.eusecom.snowsmsden"
minSdkVersion 16
targetSdkVersion 20
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:20.+'
compile 'com.android.support:appcompat-v7:20.+'
}
I recently imported my project from Eclipse to Android Studio and integrated Gradle's projectFlavors to support the different environment (DEV, QA and PROD). Although I encountered a problem with my in app billing. It seems to use the package name to query the google store but depending on my productFlavors the package name changes.
my gradle.build definition
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
Prod {
packageName 'com.test.app'
}
Qa{
packageName 'com.test.app.qa'
versionName '1.2-QA'
}
Dev{
packageName 'com.test.app.dev'
versionName '1.2-DEV'
}
}
}
repositories{
mavenCentral()
mavenLocal()
}
dependencies {
compile 'com.test.android:infra:1.0#aar'
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:4.3.23#aar'
compile files('libs/adgear-android-sdk.jar')
compile files('libs/crashlytics.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile project(':libraries:facebook')
}
Thanks for your time.
You gotta change the packageName property to applicationId.
productFlavors {
Prod {
applicationId 'com.test.app'
}
Qa{
applicationId 'com.test.app.qa'
versionName '1.2-QA'
}
Dev{
applicationId 'com.test.app.dev'
versionName '1.2-DEV'
}
}