Android studio 3.0 compile time error BUILD FAILED - android-gradle-plugin

I'm facing this issue after moving on android studio 3.0.
Whenever I try to run after couple of time then this error occurs.
Information:Gradle tasks [:app:assembleDevDebug]
Error:java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.io.IOException: Could not delete path 'D:\Akash\Final\android_main\app\build\intermediates\transforms\desugar\dev\debug\0.jar'.
Error:com.android.build.api.transform.TransformException: java.io.IOException: Could not delete path 'D:\Akash\Final\android_main\app\build\intermediates\transforms\desugar\dev\debug\0.jar'.
Error:java.io.IOException: Could not delete path 'D:\Akash\Final\android_main\app\build\intermediates\transforms\desugar\dev\debug\0.jar'.
Information:BUILD FAILED in 2s
Information:3 errors
Information:0 warnings
Solution is to rebuild or clean then run app.
Because of this i am not able to use instant run feature.
I have already tried this solution and it works works.
But why am I facing this issue frequently like 4-5 times in an hour?
P.S I do not have admin access. as mentioned HERE as accepted answer
The rest of my projects are working fine without any issue.
You may find this question as duplicate but the previous solutions are not really helpful to me at all.
Build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.github.triplet.play'
apply plugin: 'realm-android'
repositories {
maven {
url "https://XXX.XXX.com/XXX.XXX.com"
}
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
flavorDimensions "default"
project.archivesBaseName = "XXX";
signingConfigs {
release {
storeFile file (System.getenv('XXX'))
storePassword System.getenv("XXX")
keyAlias System.getenv("XXX")
keyPassword System.getenv("XXX")
}
}
playAccountConfigs {
defaultAccountConfig {
serviceAccountEmail = 'XXX-XXX-account#api-XXX-XXX.iam.XXX.com'
pk12File = file('XXX-XXX.p12')
}
}
defaultConfig {
applicationId "com.XXX.app"
minSdkVersion 16
targetSdkVersion 26
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
signingConfig signingConfigs.release
playAccountConfig = playAccountConfigs.defaultAccountConfig
ndk {
abiFilters 'armeabi-v7a'
}
}
lintOptions {
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
jumboMode true
}
productFlavors {
pro {
buildConfigField "XXX", "XXX", System.getenv("XXX")
buildConfigField "XXX", "XXX", System.getenv("XXX")
buildConfigField "XXX", "XXX", System.getenv("XXX")
buildConfigField "XXX", "XXX", System.getenv("XXX")
}
qa {
buildConfigField "XXX", "XXX", System.getenv("XXX")
buildConfigField "XXX", "XXX", System.getenv("XXX")
manifestPlaceholders = [facebookId: "XXX"]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "XXX-${variant.baseName}-${variant.versionName}.apk"
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/XXX'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
testImplementation 'junit:junit:4.12'
implementation project(path: ':instacount')
implementation project(path: ':cordova')
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:palette-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.squareup.picasso:picasso:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
implementation 'com.github.bumptech.glide:glide:3.8.0'
implementation 'net.danlew:android.joda:2.8.2'
implementation 'com.auth0.android:auth0:1.8.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
implementation 'com.amazonaws:aws-android-sdk-s3:2.4.4'
implementation 'testfairy:testfairy-android-sdk:1.+#aar'
implementation 'com.afollestad.material-dialogs:commons:0.9.0.1'
implementation 'com.jenzz.appstate:appstate:3.0.1'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.commonsware.cwac:cam2:0.7.6'
implementation 'org.parceler:parceler-api:1.1.9'
annotationProcessor 'org.parceler:parceler:1.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.jakewharton.rxbinding:rxbinding:0.4.0'
implementation 'com.caverock:androidsvg:1.2.1'
}
play {
track = 'beta'
}

I also encountered the same problem and solved it.
Try to update Realm plugin to 4.2.0.
See File handles are not released in RealmTransformer · Issue #5521 · realm/realm-java

try this one for missing java file as 1.jar,2.jar....28.jar,29.jar...as soon
in gradle.properties add the following:
android.enableD8.desugaring = true

Related

React-Native / Google Pay / Braintree / return error code "field":"authorizationFingerprint","code":"93201"

Google Payment is activated on sandbox.braintreegateway.com
Used packages for payment:
"react-native-payments"
"com.google.android.gms:play-services-wallet:19.0.1"
android/build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
}
allprojects {
repositories {
mavenLocal()
}
google()
jcenter()
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
This is my configuration where I use braintreeClientToken which is returned from server and also I use Merchant ID which I take from this page https://sandbox.braintreegateway.com/merchants/{merchantID}/merchant_accounts/info
const METHOD_DATA = [{
supportedMethods: ['android-pay'],
data: {
supportedNetworks: ['visa', 'mastercard', 'amex'],
allowedPaymentMethods: [1, 2],
currencyCode: 'EUR',
environment: 'TEST',
countryCode: 'IT',
paymentMethodTokenizationParameters: {
tokenizationType: 'GATEWAY_TOKEN',
parameters: {
gateway: 'braintree',
publicKey: braintreeClientToken,
'braintree:apiVersion': 'v1',
'braintree:merchantId': merchantID,
},
},
},
},
];
But when I finishing payment It returns error inside PaymentResponse.
"{"error":{"message":"Authorization fingerprint is invalid"},"fieldErrors":[{"field":"authorizationFingerprint","code":"93201","message":"Authorization fingerprint is required"}]}"

Could not resolve all task dependencies for configuration React-navigation error

I am having a problem with react-native-navigation packages, so I have them installed like this npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context #react-native-community/masked-view. But for some reason when I run npm run android I am getting this error for every package. ```
Deprecated Gradle features were used in this build, making it incompatible with
Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and
determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:comm
and_line_warnings
FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':app:collectReleaseDependencies'.
Could not resolve all task dependencies for configuration ':app:rele
aseRuntimeClasspath'.
Could not resolve project:#react-native-community_masked-view.
Required by:
project :app
No matching configuration of project :#react-native-commu
nity_masked-view was found. The consumer was configured to find a runti
me of a component, as well as attribute 'com.android.build.api.attributes.BuildT
ypeAttr' with value 'release' but:
None of the consumable configurations have attributes..```
This is my package json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/cli-platform-android": "^3.0.3",
"#react-native-community/masked-view": "^0.1.11",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.5",
"gradle": "^1.2.4",
"react": "17.0.1",
"react-native": "^0.64.2",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.2.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^2.18.1",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4"
},
"devDependencies": {
"#babel/core": "7.14.6",
"#babel/runtime": "7.14.6",
"#react-native-community/eslint-config": "2.0.0",
"babel-jest": "26.6.3",
"eslint": "7.14.0",
"jest": "26.6.3",
"metro-react-native-babel-preset": "0.64.0",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
}
}
This is gradle.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
This is settings.gradle
rootProject.name = 'AwesomeProject'
apply from: file("../node_modules/#react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
build gradle
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
app/build.gradle
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.awesomeproject"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
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:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// 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 from: file("../../node_modules/#react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
You are mixing different versions of react-navigation.
You can't have "react-navigation": "^4.4.4" and "#react-navigation/stack": "^5.14.5".
So install only the 5 version or the 4 as you need.

Build.grad does not load the 'index.js' Bundle when emulated on Android 9

I created my app and there is a login feature for each user to have their own profile. When I test emulating the app in androids versions 6, 7.1, 8.1, it installs normally and when it arrives in the login part, the application recognizes the user / password and logs in.
But when I emulate on Android 9, something wrong happens. After typing user / password, it does not load the next page and I realize that my 'index.js' Bundle does not load when starting the react-native run-android command.
How can I solve?
Windows 10, React Native latest version, MongoDB.
Login Code:
loginUser() {
login(this.state)
.then(response => {
if (response) {
const aux = response.data;
aux.jwt = response.token;
this.props.updateALL(aux);
Actions.main();
}
})
.catch(error => {
this.setState({ alertMessage: error.message, showIcon: true });
}); }
Package.JSON
{
"name": "ifun",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"aws-sdk": "^2.395.0",
"axios": "^0.18.0",
"date-diff": "^0.2.1",
"fuctbase64": "^1.4.0",
"google-map-react": "^1.1.2",
"install": "^0.12.2",
"native-base": "^2.8.1",
"react": "^16.6.3",
"react-dom": "^16.8.1",
"react-native": "^0.55.4",
"react-native-aws3": "0.0.8",
"react-native-carousel-view": "^0.5.1",
"react-native-elements": "^1.1.0",
"react-native-geolocation-service": "^2.0.0",
"react-native-i18n": "^2.0.15",
"react-native-image-picker": "^0.27.2",
"react-native-lightbox": "^0.8.0",
"react-native-mime-types": "^2.2.1",
"react-native-modal": "^7.0.2",
"react-native-modal-datetime-picker": "^6.0.0",
"react-native-router-flux": "^3.45.0",
"react-redux": "^5.1.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-jest": "23.4.0",
"babel-preset-react-native": "4.0.0",
"eslint-config-rallycoding": "^3.2.0",
"jest": "23.4.1",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
Build.Gradle App
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.ifun"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
multiDexEnabled true
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 {
compile project(':react-native-image-picker')
compile project(':react-native-i18n')
compile project(':react-native-geolocation-service')
implementation project(':react-native-i18n')
implementation project(':react-native-image-picker')
implementation project(':react-native-geolocation-service')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// 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'
}
when I emulate on Android 9, something wrong happens. After typing user / password, it does not load the next page and I realize that my 'index.js' Bundle does not load when starting the react-native run-android command.
How can I solve?
Verify that your existing apps work correctly on the new version of the platform. This step does not use new APIs or change the app's targetSdkVersion, but it may require minor changes.
can you try low TargetSdkVersion?
If this is resolved, please refer to here for more information.

How to access BuildConfig product flavor variables in React native android

Hi I followed the below link to create product flavours
enter link description here
I set up a variable in the flavours and I am unable to access that in the code.
build.gradle.
productFlavors {
production {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.production'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "false"
resValue "string", "MOCK_VERSION_ABCD", "false"
}
staging {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.staging'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "false"
resValue "string", "MOCK_VERSION_ABCD", "false"
}
t3st {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.test'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "true"
resValue "string", "MOCK_VERSION_ABCD", "true"
}
}
I tried to access it in my Login.js file
import { BuildCofig } from 'react-native';
loginEndpointDecider = () => {
if(BuildCofig.MOCK_VERSION){
alert('MOCK_VERSION - true');
}else{
alert('MOCK_VERSION - false');
}
}
To run the app
react-native run-android --variant=stagingDebug
I am trying to access buildConfigField MOCK_VERSION.
Could you please suggest how to get this working.
Thanks
R
I've used react-native-build-config for this. Works well but remember to set up keep rules for the generated BuildConfig class if you are using proguard. The framework that inspired this library react-native-config also works but I had problems configuring the library to work with cocoapods when targeting >=0.56 RN.

Project not synced in android studio 22.0.1 buildversion tool ubuntu

i want to sync my project in build 22.0.1 but when i set my gradle file as below it taking process sync continuously
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.sphere65.myapplication2"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22+'
compile 'com.android.support:design:22+'
}