Skip to content

Instantly share code, notes, and snippets.

@weisers
weisers / copy-native-libs-step1.gradle
Last active August 1, 2019 22:31
Ignore non-transformNativeLibsWithMergeJniLibsFor tasks
String taskNamePrefix = "transformNativeLibsWithMergeJniLibsFor"
if (!task.name.startsWith(taskNamePrefix)) {
return
}
@weisers
weisers / copy-native-libs-step2.gradle
Last active August 1, 2019 22:31
Find the task path for the build type and variant we're interested in
...
// Full description will be something like "appname_flavor_buildType"
String fullDescription = task.name
.substring(taskNamePrefix.size())
.toLowerCase()
String taskPath = null
android.applicationVariants.all { variant ->
if (fullDescription.contains(variant.flavorName.toLowerCase())
&& fullDescription.contains(variant.buildType.name.toLowerCase())) {
@weisers
weisers / copy-native-libs-step3.gradle
Last active August 1, 2019 22:31
Call to copy the native libs if a path exists
...
if (taskPath != null) {
copyNativeLibs(taskPath)
}
@weisers
weisers / copy-native-libs-step4.gradle
Last active August 1, 2019 22:30
Copy all so files from armeabi to armeabi-v7a folder
def copyNativeLibs(taskPath) {
// The native libraries will be found somewhere under the root directory
// defined below. From there, the armeabi sub-directory needs to be found.
File rootDir = new File(
projectDir,
"build/intermediates/transforms/mergeJniLibs/${taskPath}/"
)
if (!rootDir.isDirectory()) return
def srcDir = searchForDirectory("armeabi", rootDir)
if (srcDir == null) return
@weisers
weisers / copy-native-libs-step5.gradle
Last active August 1, 2019 22:29
Search for a sub-directory
private File searchForDirectory(String name, File currentDirectory) {
for (file in currentDirectory.listFiles()) {
if (file.isDirectory() && file.name == name) {
return file
}
if (file.isDirectory()) {
File result = searchForDirectory(name, file)
if (result != null) {
return result
@weisers
weisers / resconfigs-buildConfig.gradle
Last active December 7, 2020 13:33
Add optional property to define the developer's supported resource configurations
// Sets the supported res configurations. By default resources for all languages,
// densities, and screen sizes are included in each build. However, a subset can be
// specified (e.g. en,ko). This will speed up build times considerably, but should
// only be done for developer builds.
ext.supportedResConfigs = project.hasProperty('supportedResConfigs') ?
project.getProperty('supportedResConfigs').split(",") :
null
@weisers
weisers / resconfigs-gradle.properties
Last active December 7, 2020 13:28
Set the actual resource configurations you want to support locally
# Supported res configurations. If left commented, all languages, densities, and sizes
# will be included in the build. Uncomment to only include a subset. This should be a
# comma delimited list (e.g. supportedResConfigs=en,fr,ko).
supportedResConfigs=en
@weisers
weisers / resconfigs-final-build.gradle
Last active December 3, 2020 14:56
Setup build.gradle to pull in any defined resource configuration settings
// ...
apply from: "$rootDir/gradle/buildTasks.gradle"
android {
// ...
defaultConfig {
if (project.supportedResConfigs != null) {
resConfigs project.supportedResConfigs
}
// ...
}
// ...
android {
// ...
defaultConfig {
resConfigs "en"
// ...
}
// ...
}
supportedResConfigs=en,notnight,port