Skip to content

Instantly share code, notes, and snippets.

@abhishekgargx
Last active November 19, 2019 21:41
Show Gist options
  • Save abhishekgargx/daf031fb9f94fdfd985e84db57dedbe1 to your computer and use it in GitHub Desktop.
Save abhishekgargx/daf031fb9f94fdfd985e84db57dedbe1 to your computer and use it in GitHub Desktop.
Using React native 55.4 build.gradle patch for Android . FIX for duplicate resources found error in react native release or signing app.
{
"presets": ["react-native"]
}
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* this is app/build.gradle
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId ""
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
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"
signingConfig signingConfigs.release
}
}
// 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
}
}
}
}
subprojects {
project.configurations.all {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion rootProject.ext.buildToolsVersion
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
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'
}
apply plugin: 'com.google.gms.google-services'
{
"name": "MYAPP",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"resolutions": {
"*/@babel/cli": "7.0.0-beta.54",
"*/@babel/core": "7.0.0-beta.54",
"*/@babel/code-frame": "7.0.0-beta.54"
},
"dependencies": {
"axios": "^0.18.0",
"eslint": "^5.9.0",
"native-base": "2.6.1",
"prop-types": "^15.6.2",
"react": "16.3.1",
"react-devtools": "^3.4.3",
"react-native": "0.55.4",
"react-native-animatable": "^1.3.0",
"react-native-button": "^2.3.0",
"react-native-camera": "^1.4.1",
"react-native-image-picker": "^0.27.1",
"react-native-router-flux": "^4.0.6",
"react-navigation": "^2.18.2",
"react-redux": "^5.1.1",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-jest": "23.4.2",
"babel-preset-react-native": "4.0.0",
"jest": "23.5.0",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"app/resources/fonts",
"app/resources/img"
]
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// rename project_build.gradle to build.gradle
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = "27.1.1"
}
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"
}
}
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
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
}
}
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
allprojects {
repositories {
mavenCentral()
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"
}
maven {
url "https://jitpack.io"
}
maven {
url 'https://maven.google.com/'
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// So basically you edit the /node_modules/react-native/react.gradle file
// and add the doLast right after the doFirst block, manually.
doFirst { ... }
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("ldpi").call()
moveFunc.curry("mdpi").call()
moveFunc.curry("hdpi").call()
moveFunc.curry("xhdpi").call()
moveFunc.curry("xxhdpi").call()
moveFunc.curry("xxxhdpi").call()
}
@jasulan1101
Copy link

I have an error

  • What went wrong:
    Execution failed for task ':app:processReleaseResources'.

Failed to process resources, see aapt output above for details.

/Users/macpro/Desktop/EntGlobusOffline/EntGlobusOffline/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml:21
:23-42: AAPT: No resource found that matches the given name (at 'icon' with value '@mipmap/ic_launcher').

/Users/macpro/Desktop/EntGlobusOffline/EntGlobusOffline/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml:22:24-40: AAPT: No resource found that matches the given name (at 'label' with value '@string/app_name').

/Users/macpro/Desktop/EntGlobusOffline/EntGlobusOffline/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml:23:24-39: AAPT: No resource found that matches the given name (at 'theme' with value '@style/AppTheme').

/Users/macpro/Desktop/EntGlobusOffline/EntGlobusOffline/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml:27:28-44: AAPT: No resource found that matches the given name (at 'label' with value '@string/app_name').

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processReleaseResources'.

Failed to process resources, see aapt output above for details.

@abhishekgargx
Copy link
Author

@alenzhasulan
@mipmap/ic_launcher is my APP Icon
@String/app_name is my APP name
same goes with other values makes sure you created new or hardcode one

@ooca-big
Copy link

This would work fine for multiple product flavours.

            doFirst { ...  }
            doLast {
                def moveFunc = { resSuffix ->
                    File originalDir = file("$buildDir/generated/res/react/${variant.getFlavorName()}/${variant.name}/drawable-${resSuffix}");
                    if (originalDir.exists()) {
                        File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
                        ant.move(file: originalDir, tofile: destDir);
                    }

                }
                moveFunc.curry("ldpi").call()
                moveFunc.curry("mdpi").call()
                moveFunc.curry("hdpi").call()
                moveFunc.curry("xhdpi").call()
                moveFunc.curry("xxhdpi").call()
                moveFunc.curry("xxxhdpi").call()
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment