Android flavors: Add an external library on a specific flavor - android

On my project gradle, i have declared two flavors:
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mypackage"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "myFlavor"
productFlavors {
firts{
dimension "myFlavor"
applicationId "com.mypackage.first"
}
second{
dimension "myFlavor"
applicationId "com.mypackage.second"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
Now i need to include and use an external jar library only to second flavor.
How can i do?

Its as Simple as replacing implementation with <flavor-name>Implementation <library>
Lets say you want to include com.android.support:design:27.1.1 only for second flavor. You can achieve it as follows:
dependencies {
...
secondImplementation 'com.android.support:design:27.1.1'
...
}

Related

How to resolve dependency for ':app#releaseUnitTest/compileClasspath'

Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not find any version that matches com.android.support:appcompat-v7:29.+.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
defaultConfig {
applicationId "com.example.usman.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:29.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

How to change the "min Sdk version"?

I'm changing the minSdk version but when I build/generate apk(s) I get this error:
failed linking references.
I have tried Invalidating Caches and restarting
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.clubs"
minSdkVersion 21
targetSdkVersion 27
vectorDrawables.useSupportLibrary = true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'nl.psdcompany:duo-navigation-drawer:3.0.0'
implementation 'com.github.ApendIr:slider:1.0'
implementation 'com.azoft.carousellayoutmanager:carousel:1.2.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
I don't know if this is what is resulting to the apps crashing in some phones
Set the min SDK version within your project's AndroidManifest.xml file:
<uses-sdk android:minSdkVersion="21"/>

implementation error - picasso:2.71828 (More than one file was found with OS independent path)

An error occurred when I wrote this syntax to add the picasso library.
(More than one file was found with OS independent path 'okhttp3/internal/publicsuffix/publicsuffixes.gz')
My android gradle is as follows!!
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.i203_153.smarthome"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/jackson-annotations-2.1.2.jar')
implementation files('libs/com.fasterxml.jackson.core.jar')
implementation files('libs/com.fasterxml.jackson.databind.jar')
}
How do I fix the following errors? Please help me!!
Try this
compile 'com.squareup.picasso:picasso:2.5.0'

android compiler error, no error in the file

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.oneca.myapplication"
minSdkVersion 22
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/mysql-connector-java-8.0.11.jar')}
this is the data in the build.gradle. No grammar error in the java file. what is wrong.
Update your minSdkVersion.
minSdkVersion 24
because your lib implementation files('libs/mysql-connector-java-8.0.11.jar')}
not support below SdkVersion 24.

Building gradle with cmake

I'm getting the error "Unable to get the CMake version located at C:\Users\Mujtaba Faizi\Downloads\cmake-3.10.1\bin" but I gave the version 3.10.1 in build.gradle and the path in local.properties. I've been at it for so long. Thanks in advance.
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.mujtaba.basicai"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jniLibs/armeabi-v7a'] }
}
externalNativeBuild {
cmake {
version "3.10.1"
path 'CMakeLists.txt'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile files('libs/libandroid_tensorflow_inference_java.jar')
compile 'com.flurgle:camerakit:0.9.13' //for camera access purposes
}
local.properties:
cmake.dir=C\:\\Users\\Mujtaba Faizi\\Downloads\\cmake-3.10.1
ndk.dir=C\:\\Users\\Mujtaba Faizi\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=C\:\\Users\\Mujtaba Faizi\\AppData\\Local\\Android\\Sdk
This thread is kind of old. But in my case I did not added cmake version to gradle file instead I just had to add path to local.properties
cmake.dir=/home/rafal/Pobrane/cmake-3.11.0

Categories

Resources