Gradle upgrade 4.1 doesn't load versionCode and versionName - android-gradle-plugin

I upgraded my gradle to 4.1
project.ext.set("currentGradleVersion", "4.1")
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
I moved all the "compile" to "implementation" since "compile" is deprecated.
Also changed variant.outputs.each to variants.outputs.all
The apk generates with the correct versionName
But when I used aapt command "./aapt d badging **.apk"
All the below are returned as empty, what went wrong?
versionCode='' versionName='' platformBuildVersionName=''

After some ... long.. researches :
Here are some solutions to update the versionCode and versionName:
Gradle 3.0.0 alpha variant output issue
Gradle plugin 3.0 rewrite versionName
In a Brief :
It is something no more supported by the latest gradle version.
To fix it, you can ADD this piece of code in your current code :
applicationVariants.all { variant ->
...
variant.outputs.all { output ->
...
output.setVersionCodeOverride(VERSION_CODE_INTEGER)
output.setVersionNameOverride(VERSION_NAME_STRING)
...
}
...
}
}

Related

Execution failed for task ':realm:stripDebugDebugSymbols'

After installing realm in react native and setting up all necessary things console give me this error after starting project (npm run android);
Execution failed for task ':realm:stripDebugDebugSymbols'. NDK at C:\Users\123\AppData\Local\Android\Sdk\ndk\21.4.7075529 did not have a source.properties file.
I check ndk in android studio (after opening project in it) in Android SDK --> SDK tools sections, the ndk already installed. I also change the ndk version (one by one) in android/build.gradle according to some other stackoverflow solutions but didn't work. Below is android/build.gradle code;
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"//"25.1.8937393"//"21.1.6528147"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
This is a android studio screen shot of sdk tools SDK tools

React-Native Android Build Failure: Execution failed for task ':app:processDebugResources'. Failed to process resources

I cannot figure out what is wrong with the build. I tried the common solutions of running ./gradlew clean as well as adding the android.enableAapt2=false to the gradle.properties.
The google-services.json folder is at the /android/app level.
Im at a loss right now as to how to get past this one.
If I forgot to include something useful please lmk and I will update.
Cheers
Error Output
Configure project :app
WARNING: The specified Android SDK Build Tools version (26.0.1) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.3.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Configure project :react-native-google-analytics-bridge
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Configure project :react-native-radar
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Task :app:processDebugGoogleServices
Parsing json file: /Users/kyletreman/18F/courier_test_app/android/app/google-services.json
/Users/kyletreman/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/64df69838d7c555de168bdcf18f3be5c/res/values/values.xml:113:5-69: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/kyletreman/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/64df69838d7c555de168bdcf18f3be5c/res/values/values.xml:113:5-69: AAPT: error: resource android:attr/ttcIndex not found.
error: failed linking references.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugResources'.
Failed to process resources, see aapt output above for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 2s
50 actionable tasks: 3 executed, 47 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
/android/app/build.gradle
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.courier_test_app.app"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'com.android.support:support-v13:27.1.1'
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-radar')
implementation project(':react-native-google-analytics-bridge')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
/android/build.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.google.gms:google-services:4.0.0'
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
From the error log I can see that appcompat-v7-23.0.1 is still being used. So, it would probably help to update resolutionStrategy:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
force 'com.android.support:appcompat-v7-23.0.1'
}
}
Also you need to place that resolution strategy block in your app/build.gradle
Fixed
I was able to get help from someone familiar with the native side and he helped me sort out quite a few errors.
implementation order matters, this was the order that worked for me
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.android.support:support-v4:27.1.1"
implementation 'com.android.support:support-v13:27.1.1'
implementation "com.android.support:appcompat-v7:27.1.1"
implementation(project(':react-native-firebase'))
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation project(':react-native-radar')
implementation project(':react-native-google-analytics-bridge')
I need to move the configuration resolution strategies to the android/app/build.gradle file, mine were at the wrong level. I also had to alter versions of the support and appcompat packages. You can find dependencies via
./gradlew app:dependencies
from the android folder. The issue was one of the dependencies was pulling a older version, which was fixed by using the following in the resolutionStrategies.
force 'com.android.support:appcompat-v7:27.1.1'
The next change that needed to be made was the following line in the MainApplication.java
return BuildConfig.DEBUG;
to this
return <app_name>.BuildConfig.DEBUG;
I also removed the enableaapt2=false
The last tip I can give is that naming matters, don't rename your app unless its absolutely necessary and make sure it changes across the Main java files and AndroidMainfest.xml.
UPDATED
I realized my debugger was not connecting, it was because I removed some implementation packages that supported firebase, adding them back fixed the issue. Add the following below the firebase implementation.
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.1"
put this code at the end of android/build.gradle
use your own numbers for the compileSdkVersion and buildToolsVersion
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
}
}
}
}

Could not resolve com.android.support:design:26.1.0

I have been having this problem for quite a while, that my com.android.support:design:26.1.0 fails me and I have no clue what to change anymore.
These are my files for module gradle.
Build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.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'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.google.android.gms:play-services-vision:9.4.0'
// compile 'com.android.support:design:26.1.0'
}
//apply plugin: 'com.google.gms.google-services'
The project gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter({ url "http://jcenter.bintray.com/" })
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// classpath 'com.google.gms:google-services:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter({ url "http://jcenter.bintray.com/" })
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Error:Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:design:26.1.0.
Error:Unable to resolve dependency
for ':app#release/compileClasspath': Could not resolve
com.android.support:design:26.1.0.
Error:Unable to resolve dependency
for ':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:design:26.1.0.
Error:Unable to resolve dependency
for ':app#debugAndroidTest/compileClasspath': Could not resolve
com.android.support:design:26.1.0.
Error:Unable to resolve dependency
for ':app#debug/compileClasspath': Could not resolve
com.android.support:design:26.1.0.
And only the 'Snackbar' function does not work but rest of it seems fine.
When I change the design to 25.1.0 version instead, it works but it clashes with other 26.1.0 ones so it's not recommended by the Android Studio. Anyone..?
I have tried putting the
compile 'com.android.support:design:26.1.0'
instead of implement, it does not work. When I tried to change the whole thing to either 25.4.0 or any other 25 version, a lot of other things doesnt compile as well. I have unchecked the Offline work, tried removing / adding maven directory, un-commenting a few more of dependencies, changing all to compile instead of implement but just gives me more errors.
Yes I have updated all my SDKs to the newest but I have a feeling that Gradle just cannot download certain dependencies from the websites that's why I cannot download any more of the other dependencies. (Although my off-line work is unchecked)
Also, whatever that are uncommented in the code above, it means I have tried inputting those lines but it did not solve the issue or rather created more issues.
Here is the way i found it please try the below
Go to File->Settings->Build, Execution, Deployment->Gradle->Uncheck Offline work option.
Try this once ,instead of implementing compile the design support gradle code
compile 'com.android.support:design:26.1.0'
and remove this
implementation 'com.android.support:design:26.1.0'
Problem that I realized in the end was that when I was setting up the android proxy, I have only set up 1 proxy which was for HTTP and did not realize that HTTPS proxy was not set up.
So after fixing that issue by setting HTTPS proxy, there was no more problems.

Android Studio 2.2 update cause DefaultManifestParser cannot be resolve

Recently I updated android studio to android studio 2.2 and using gradle 2.14.1. However, com.android.builder.core.DefaultManifestParser cannot be resolve after the update. Below are the codes that I am using. Any recommend workaround to solve this issue? Thanks
defaultConfig {
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
applicationId = manifestParser.getPackage()
versionName = manifestParser.getVersionName()
versionCode manifestParser.getVersionCode()
minSdkVersion manifestParser.getMinSdkVersion()
targetSdkVersion manifestParser.getTargetSdkVersion()
multiDexEnabled true
}
My defaultConfig setting is similar to yours and it's successfully built,
defaultConfig {
def manifestFile = (File) android.sourceSets.main.manifest.srcFile
def manifestParser = new DefaultManifestParser(manifestFile)
//noinspection GroovyAssignabilityCheck
applicationId = manifestParser.getPackage()
minSdkVersion 18
targetSdkVersion 23
//noinspection GroovyAssignabilityCheck
versionName = manifestParser.getVersionName()
//noinspection GroovyAssignabilityCheck
versionCode = manifestParser.getVersionCode()
}
so I guess probably the required *.jar hasn't been successfully downloaded during the IDE update. Could you double check whether the file builder-2.2.0.jar exists under the IDE folder(e.g., C:\Program Files\Android\android-studio_2.2\gradle\m2repository\com\android\tools\build\builder\2.2.0). If it does exist, can do a further checking to make sure the file DefaultManifestParser.class is really inside folder \com\android\builder\core by extracting builder-2.2.0.jar.
If the above mentioned file and class do exist, can also try using import com.android.builder.core.DefaultManifestParser, however, it's a bit weird that we have to use this.
Just think of there is another thing to check is the Gradle plugin class path, it should be like this
classpath 'com.android.tools.build:gradle:2.2.0'
I have same troubleļ¼Œand reback gradle version to 2.1.3 it is working
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}

Android studio Gradle BUILD SUCCESSFUL despite cannot resolve android.support.v4

Despite Gradle is telling me build succesfull (and I can run the app), android studio cannot resolve "import android.support.v4" and for the support.v7 lib can only resolve appcompat... I tried the button "Use Sync project with gradle files", upgraded my build tools to the latest version but I still have this error.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "me.myapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'org.jsoup:jsoup:1.8.2'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
}
Please help me fix this!
Follow the below steps.
Run all updates: Update android studio and SDK to the latest version.
go to File->invalidate caches/Restart.
Hope this fixes the problem.