Gradle buildTypes incompatible types - android

I am new to Gradle build tool. I want to create constant OPEN_WEATHER_MAP_API_KEY in android app but I am getting following error
build.gradle
`apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.android.sunshine.app"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.all { variant ->
variant.buildConfigField "String", "OPEN_WEATHER_MAP_API_KEY", "1"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}`
I tried multiple things but can not able to resolve it.

Replace:
variant.buildConfigField "String", "OPEN_WEATHER_MAP_API_KEY", "1"
with:
variant.buildConfigField "String", "OPEN_WEATHER_MAP_API_KEY", '"1"'
The String needs to be quoted. If the field was an int, you could have left it unquoted.

Related

Room Persistence inside of Lib

I am looking for a good way to import Room Persistence inside of my Lib to export .aar . I have the following issue that .aar cannot handle dependencies.
When I export my arr and import into another project as lib, it seems as it has no scope to room.
my lib Gradle file :
apply plugin: 'com.android.library'
apply plugin: 'maven'
archivesBaseName = '*****'
android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 5
versionName "1.1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Write out the current schema of Room
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
deployerJars
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'android.arch.persistence.room:runtime:1.1.0-beta3'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.0-beta3'
}
Thanks.

Gradle cannot find theme

I am trying to simply build a second module in my Android project. I have refered to another module, because there are some Activities and classes I want to reuse. This is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "nl.minerall.sapphire.browser"
minSdkVersion 19
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
}
lintOptions {
disable "MissingTranslation"
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile project(path: ':sapphirelib')
compile project(path: ':app')
}
The build.gradle of sapphirelib is:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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'
})
testCompile 'junit:junit:4.12'
compile files('libs/simple-xml-2.7.1.jar')
compile project(path: ':Zebra_SDK_DS3678')
}
And of app:
apply plugin: 'com.android.application'
android {
signingConfigs {
demo {
keyAlias 'FlexDemo'
keyPassword '******'
storeFile file('/path/to/file.jks')
storePassword '******'
v2SigningEnabled false
}
full {
keyAlias 'PocketFull'
keyPassword '****'
storeFile file('/path/to/file.jks')
storePassword '*****'
v2SigningEnabled false
}
}
compileSdkVersion 19
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "nl.minerall.sapphire.pocket"
minSdkVersion 19
targetSdkVersion 19
}
productFlavors {
full {
applicationId "nl.minerall.sapphire.pocket.full"
signingConfig signingConfigs.full
resValue "string", "app_name", "Sapphire Pocket"
versionCode 13
versionName "Flex 2.0.25"
}
demo {
applicationId "nl.minerall.sapphire.pocket.demo"
signingConfig signingConfigs.demo
resValue "string", "app_name", "Pocket Demo"
versionCode 12
versionName "Flex 1.13 DEMO"
}
ipsdemo {
applicationId "nl.minerall.sapphire.pocket.ipsdemo"
signingConfig signingConfigs.demo
resValue "string", "app_name", "Pocket IPS Demo"
versionCode 12
versionName "Flex 1.13 IPS DEMO"
}
sourceSets.ipsdemo.root = "src/demo"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
}
lintOptions {
disable "MissingTranslation"
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile project(path: ':sapphirelib')
}
When I build, I get the error
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.NoActionBar'.
and I am thrown into a values-v21.xml file that is apparently auto-generated. The styles.xml I am using is:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
It completely beats me where the android:Theme.Material.Light.NoActionBar comes from ...

In my app I have a module(a library).When I set 'productFlavors' in the library build.The application can't dependency the module

In my app I have a module(basiclib is a library).When I set 'productFlavors' in the library build.I build the project.The application has more import error.It can't import the basiclib package,and the bascilib dependencies's package.
But I remove 'productFlavors' of basiclib.every thing is right.
Application build :
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
dataBinding {
enabled true
}
defaultConfig {
applicationId "xxxx"
minSdkVersion 11
targetSdkVersion 22
versionCode 18000
versionName "1.0.0"
}
lintOptions {
abortOnError false
}
buildTypes {
release {
signingConfig signingConfigs.myConfig
minifyEnabled true;
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
}
}
flavorDimensions "url", "theme"
productFlavors {
sit {
buildConfigField 'String', 'API_URL', '"xxxx"'
dimension "url"
}
uat {
buildConfigField 'String', 'API_URL', '"xxxx"'
dimension "url"
}
prd {
buildConfigField 'String', 'API_URL', '"xxx"'
dimension "url"
}
themewhite {
buildConfigField 'String', 'theme', '"white"'
dimension "theme"
}
}
sourceSets {
sit {
java.srcDirs = ['src/sit_uat/java']
}
uat {
java.srcDirs = ['src/sit_uat/java']
}
prd {
java.srcDirs = ['src/prd/java']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
sitCompile 'com.bugtags.library:bugtags-lib:latest.integration'
prdCompile 'com.umeng.analytics:analytics:latest.integration'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.0'
compile 'com.jiechic.library:xUtils:2.6.14'
compile 'com.loopj.android:android-async-http:1.4.7'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
// Did'n work.
compile project(path: ':basiclib')
}
Library build(basiclib)
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "url"
productFlavors {
sit {
buildConfigField 'String', 'API_URL', '"xxxxx"'
dimension "url"
}
uat {
buildConfigField 'String', 'API_URL', '"xxxxx"'
dimension "url"
}
prd {
buildConfigField 'String', 'API_URL', '"xxxxx"'
dimension "url"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.google.code.gson:gson:2.5'
compile 'io.realm:realm-android-library:2.2.2'
compile 'com.android.databinding:library:1.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.android.support:appcompat-v7:23.2.1'
}
I had the same problem and after a lot of searching I found the following documentation entry:
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Referencing-a-Library
In short: Per default, in library modules only the default configuration (release / no flavour) is visible to other modules. To access the different flavours from your main module, add
publishNonDefault true
in the android section of your library's build.gradle file.
Then you have to add different flavours for the main module as well, they can be empty declarations. In the dependency section of your build.gradle reference the module as follows:
flavor1Compile project(path: ':yourlib', configuration: 'flavor1Release')
flavor2Compile project(path: ':yourlib', configuration: 'flavor2Release')

How to change suffix of apk based on buildtype

I want to change the generated name of the .apk file in my build gradle. based on which buildtype i choose. It automatically appends "-release" or "-debug".
How can I change this?
Build gradle file
android {
signingConfigs {
testapp {
storeFile file("itsASecret")
storePassword "itsASecret"
keyAlias "itsASecret"
keyPassword "itsASecret"
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
def versionPropertiesFile = file('version.properties')
if (versionPropertiesFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropertiesFile))
def code = versionProps['VERSION_CODE'].toInteger() + 1
versionProps['VERSION_CODE'] = code.toString()
versionProps.store(versionPropertiesFile.newWriter(), null)
defaultConfig
{
applicationId "com.testapp.app"
minSdkVersion 19
targetSdkVersion 22
versionCode code
versionName "1.02.00"
multiDexEnabled true
setProperty("archivesBaseName", "TestApp_" + "$versionName" + "_" + "$versionCode")
}
} else {
throw new GradleException("Could not read version.properties!")
}
buildTypes
{
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.testapp
}
debug {
debuggable true
signingConfig signingConfigs.testapp
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
signingConfig signingConfigs.railway
}
}
I tried something like
applicationIdSuffix "_DEBUGTEST"
or
versionNameSuffix "_DEBUGTEST"
Filename:
TestApp_1.02.00_458-release.apk
TestApp_1.02.00_458-debug.apk
But this is not working :-(
EDIT:
I do have a common library with another build gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'commons-codec:commons-codec:1.10'
compile 'de.mindpipe.android:android-logging-log4j:1.0.3'
compile 'log4j:log4j:1.2.16'
compile 'org.slf4j:slf4j-api:1.6.4'
compile 'org.slf4j:slf4j-log4j12:1.6.4'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'commons-net:commons-net:3.3'
compile 'net.lingala.zip4j:zip4j:1.3.2'
compile 'com.jjoe64:graphview:4.0.1'
}

Gradle DSL method not found: 'applicationId()'

I am getting this error on building the application in Android Studio.
Gradle DSL method not found: 'applicationId()'
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
applicationId "com.ms.knowursensor.android"
minSdkVersion 13
defaultConfig {
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "sensorgraph"
stl "c++_static"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
debuggable = true
}
}
debug {
debuggable true
jniDebuggable true
}
}
sourceSets {
main {
jniLibs.srcDir 'src/main/jniLibs'
// use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build
}
}
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
This issue came when i recently update the SDK. How to resolve this issue?
Move applicationId and minSdkVersion into your defaultConfig closure.

Categories

Resources