Gradle build error after updating android studio: NumberFormatException for versionCode - android-studio

I got an error I had not before:
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'.
> Failed to query the value of property 'packageName'.
> java.lang.NumberFormatException: For input string: "${versionCode}"
The android studio version is:
Android Studio 4.1.1
Build #AI-201.8743.12.41.6953283, built on November 5, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
The build.gradle(:app) file contains the following:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' //< for image visualization with glide
//Serialization
apply plugin: 'kotlinx-serialization'
android {
signingConfigs {
release {
storeFile file('xxxx.jks')
storePassword 'xxxxxxx'
keyPassword 'xxxxxxxx'
keyAlias 'my-app'
}
}
compileSdkVersion propCompileSdkVersion
buildToolsVersion propBuildToolsVersion
defaultConfig {
applicationId "com.user.myapp"
minSdkVersion propMinSdkVersion
targetSdkVersion propTargetSdkVersion
versionCode 3
versionName "2.0-beta.26"
manifestPlaceholders = [versionCode:"3", versionName:"2.0-beta.26"]
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
resValue "string", "app_name", "myapp-dev"
}
optimizedDebug {
initWith debug
minifyEnabled false
applicationIdSuffix ".optimizedDebug"
debuggable false
resValue "string", "app_name", "myapp-optimized-dev"
}
debugProd {
initWith debug
minifyEnabled false
applicationIdSuffix ".debugProd"
debuggable true
resValue "string", "app_name", "myapp-logs-in-prod"
}
release {
minifyEnabled false
resValue "string", "app_name", "myapp"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.resValue "string", 'images_file_path', "Android/data/\"${applicationId}\"/files/Pictures"
}
/* Necessary to have Parcelable / #Parcelize functionalities */
androidExtensions {
experimental = true
}
lintOptions {
checkReleaseBuilds false
abortOnError true
}
}
dependencies {
...
}
repositories {
mavenCentral()
}
I have invalidated the caches and restarted several times, nothing changes.
I would like to pinpoint exactly what happens, to at least be able to understand what causes gradle to be confused.
Can anyone point me to a step by step run of gradle to find what is the problem ?

I found that in the manifest I had the following error annotated by android studio:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myapp"
android:versionCode={$versionCode}
android:versionName={$versionName}
>
...
</manifest>
It looks that in the 4.1.1 release of android studio,
android:versionCode={$versionCode}
is not working anymore.
This post https://commonsware.com/blog/2020/10/14/android-studio-4p1-library-modules-version-code.html says that we should no more use VERSION_CODE and VERSION_NAME.
So I remove them entirely from my code and replaced it with custom buildConfigField gradle variables:
in gradle:
defaultConfig {
...
buildConfigField 'int', 'MYAPP_VERSION_CODE', "3"
buildConfigField 'String', 'MYAPP_VERSION_NAME', "\"2.0-beta.26\""
...
}
in manifest remove the part referencing android:versionXXXX:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.myapp"
>
...
</manifest>
in kotlin code to display code and name version:
val versionCode = BuildConfig.MYAPP_VERSION_CODE.toString()
val versionName = BuildConfig.MYAPP_VERSION_NAME
It works nicely after that.

Related

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. error in android studio version dolphin 2021.3.1

My Android Studio Current version Dolphin 2021.3.1 patch 1, in my project I am getting following build error in empty project while adding a fresh dependency. ie.
implementation 'io.github.amrdeveloper:codeview:1.3.7'
getting from here >>> https://amrdeveloper.github.io/CodeView/install/#main-features
I have already checked lots of Solutions related this question but no luck.
build.gradle:project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
build.gradle:module
plugins {
id 'com.android.application'
}
android {
namespace 'com.myvpn.myapp'
compileSdk 32
defaultConfig {
applicationId "com.myvpn.myapp"
minSdk 21
targetSdk 32
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
//added these two dependencies
implementation 'io.github.amrdeveloper:codeview:1.3.7'
implementation 'com.github.AmrDeveloper:CodeView:1.3.7'
}
Build Output.
enter image description here
i have tried turn off the Toggle Offline Mode .
enter image description here

Android Studio build variant problems

I am having difficulty getting Android Studio to build the right build variant — or even to let me select a build variant at all, sometimes.
Basically I have two different versions of my project a free and a "full" version. Package ids are "com.mycompany.myproj" and "com.mycompany.myprojfree".
Once I've specified "myproj" and "myprojfree" flavors and "release" and "debug" buildtypes, Android Studio produces four variants in the list: myprojDebug, myprojfreeDebug, myprojfreeRelease, and myprojRelease.
Problem is, selecting one of these doesn't reliably select the variant for building, debugging, etc. For instance, I'll select myprojDebug, hit Debug, and myprojfreeDebug will build (as can be seen in the console), and the free version will open on the attached device.
Moreover, sometimes I can't even select one or more of the build variants in the build variant pane. I can click on it, but it doesn't change. But sometimes if I change it to something else first it'll let me go back and change the non-changing one.
I've seen posts referring to similar-sounding problems and have followed all the suggestions — cleaning, rebuilding, deleting .idea, deleting the build folder, Invalidate Caches/Restart, deleting app.iml, etc. — all to no avail.
It may be worth noting that all of this worked fine until yesterday, when I updated from Android Studio 3.1 to 3.4.1.
Here's a simplified version of my app build.gradle:
apply plugin: 'com.android.application'
android {
defaultConfig {
versionCode ...
multiDexEnabled true
vectorDrawables {
useSupportLibrary true
}
minSdkVersion 15
targetSdkVersion 28
}
compileSdkVersion 28
signingConfigs {
myproj {
keyAlias ...
keyPassword ...
storeFile file('...')
storePassword ...
}
myprojfree {
keyAlias ...
keyPassword ...
storeFile file('...')
storePassword ...
}
}
flavorDimensions "tier"
productFlavors {
myproj {
signingConfig signingConfigs.myproj
applicationId 'com.mycompany.myproj'
}
myprojfree {
signingConfig signingConfigs.myprojfree
applicationId 'com.mycompany.myprojfree'
}
}
buildTypes {
release {
debuggable false
buildConfigField "Boolean", "MY_DEBUG_MODE", "false"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
debug {
debuggable true
buildConfigField "Boolean", "MY_DEBUG_MODE", "true"
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
configurations {
implementation.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
...
}
I'm pretty sure the problem came from a non-synchrony between files and Gradle sync.
So do `File/Sync Project with Gradle Files' after a change of Build Variant.
Then clean project, rebuild and run.

Android studio 3: Could not find the AndroidManifest.xml file

after migrating to Android studio 3 I'm unable to compile as I' have folowing errors:
Error:Could not find the AndroidManifest.xml file, using generation
folder
[/home/salacr/git/Evotech/app/build/generated/source/apt/debug])
Error:Parceler: Code generation did not complete successfully. For
more details add the compiler argument -AparcelerStacktrace
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
It might be connected with usage of android anotation my app/build.gradle looks like this:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
def AAVersion = '4.3.1'
def parcelerVersion = '1.1.9'
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
applicationId "com.my.app"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
signingConfigs {
release {
storeFile file("******")
storePassword "******"
keyAlias "******"
keyPassword "******"
}
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
/*
// map for the version code
project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
*/
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "org.parceler:parceler-api:$parcelerVersion"
annotationProcessor "org.parceler:parceler:$parcelerVersion"
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:multidex:1.0.2'
}
I'm unable to find the root cause for this, any suggestions?
I tried diferent graddle versions as well as using different buildToolsVersion tools, but without effect.
Any suggestions?
Thanks!
EDIT 1: I have found out that problem is here:
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
Without this everything works as expected. IT seams that this config isn't compatible with androidanotations in new Android studio
EDIT 2: There is already issue in androidanotation: https://github.com/androidannotations/androidannotations/issues/2034
I had similar issue and solved my problem when I updated android annotation version from 4.4.0 to 4.5.0.
Add the following code in build.gradle file under defaultConfig
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"androidManifestFile":"$projectDir/src/main/AndroidManifest.xml".toString()
]
}
}
I solved this problem changed graddle version:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
I had similar issue and solved my problem when I updated android annotation version from 4.4.0 to 4.6.0.

in Android Studio Error “duplicate entry: com/google/android/gms/analytics/internal/Command$1.class”

Here is my gradle code
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary 'org.apache.http.legacy'
compileOptions.encoding = 'ISO-8859-1'
defaultConfig {
multiDexEnabled true
applicationId "com.mujihamzale.Ayat-AyatMerdu"
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'joda-time:joda-time:2.2'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile files('libs/libGoogleAnalyticsServices.jar')
}
But when running the application on android studio 2.1.3, I get the following error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class
I have been for days to look for a solution, Please Could you tell me how to solve this problem?

Error:Execution failed for task :app:transformClassesWithJarMergingForRelease

Hello i have a problem and i need some help
i want to integrate facebook Sdk in my project to facebook ads to get installs and i got some errors
This is the error :
Error:Execution failed for task'
:app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry: android/support/v4/media/TransportPerformer.class
And this is my build.gradle code :
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.example.example"
minSdkVersion 15
targetSdkVersion 24
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call}
}
`repositories {
mavenCentral()
}
dependencies {
compile('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'}`
Have you tried to run './gradlew clean' in your project?

Resources