When making an android release build, with this config in my project:
// from myapp/android/build.gradle
classpath 'com.android.tools.build:gradle:3.1.3'
...
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
implementationSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = "27"
it fails with this errors:
> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: /Users/user/...path.../android/app/build/generated/assets/react/release/index.android.bundle
bundle: Done writing bundle output
bundle: Copying 20 asset files
bundle: Done copying assets
error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values-v26/values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values/values.xml:251:5-69: AAPT: error: resource android:attr/fontStyle not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values/values.xml:251:5-69: AAPT: error: resource android:attr/font not found.
/Users/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/a2910aa9b026ed50223f50c36bfea612/res/values/values.xml:251:5-69: AAPT: error: resource android:attr/fontWeight not found.
error: failed linking references.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-youtube:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
* 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 3m 13s
191 actionable tasks: 16 executed, 175 up-to-date
error Command failed with exit code 1.
I've done the same as mentioned in this react-native-audio's PR named "Use sdk, buildTools and support lib versions from root project".
Go to the node_modules/react-native-youtube/android/build.gradle file and:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 23
def DEFAULT_BUILD_TOOLS_VERSION = "23.0.1"
def DEFAULT_TARGET_SDK_VERSION = 22
def DEFAULT_SUPPORT_LIB_VERSION = "23.1.0"
android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 16
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
}
def supportVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:${supportVersion}'
compile 'com.facebook.react:react-native:+'
}
Does it deserve a PR if considered as a not-dirty fix?
Definitely deserves to be merged!
For those facing this or a similar issue when using this or any react native library, I found this generic solution to be good enough for me:
https://stackoverflow.com/questions/24494077/gradle-force-build-tools-version-on-third-party-libraries
It does seem a bit dirty, but I have seen it used in many android projects:
@cadesalaberry works perfect!!
great solution !
Most helpful comment
It does seem a bit dirty, but I have seen it used in many android projects:
https://github.com/getsentry/sentry-react-native/blob/9921607204d750ea8a8c3f0246fd5cc068a77ca1/android/build.gradle#L1-L9