Skip to content

Commit

Permalink
android: Make it possible to configure ndkVersion from extension
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jul 10, 2024
1 parent c5c9107 commit ec22134
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ android {
### Other Changes

- **android:** Use `ANDROID_BUILD_TOOLS_VERSION` env variable for `buildToolsVersion` if the option is not configured (#132)
- **android:** Add the option `redmadrobot.android.ndkVersion` to specify NDK version for all android modules
- **android:** Remove the workaround for Explicit API enabling as the issue has been [fixed](https://youtrack.jetbrains.com/issue/KT-37652) in Kotlin 1.9
- **android:** Remove disabling of build features `aidl`, `renderScript` and `buildConfig` as they are already disabled by default in new versions of AGP
- **kotlin:** Deprecate accessor `kotlinCompile`.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ redmadrobot {
// Build Tools version to be used in all android modules.
buildToolsVersion = System.getenv("ANDROID_BUILD_TOOLS_VERSION")

// NDK version to be used in all android modules.
ndkVersion = System.getenv("ANDROID_NDK_VERSION")

// Filter for test tasks that should be run on ':test'.
testTasksFilter = { taskProvider -> taskProvider.name.endsWith("ReleaseUnitTest") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public interface AndroidOptions {
*/
public val buildToolsVersion: Property<String>

/**
* NDK to be used in all android modules.
* By default, uses the version from the environment variable `ANDROID_NDK_VERSION` if it is set.
*/
public val ndkVersion: Property<String>

/**
* Filters test tasks that should be run on ':test'.
* It is useful if you don't want to run tests for all build variants when run 'test' task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ internal abstract class AndroidOptionsImpl @Inject constructor(
buildToolsVersion
.convention(providers.environmentVariable("ANDROID_BUILD_TOOLS_VERSION"))
.finalizeValueOnRead()
ndkVersion
.convention(providers.environmentVariable("ANDROID_NDK_VERSION"))
.finalizeValueOnRead()
testTasksFilter
.convention { taskProvider -> taskProvider.name.endsWith("ReleaseUnitTest") }
.finalizeValueOnRead()
Expand All @@ -48,6 +51,7 @@ internal abstract class AndroidOptionsImpl @Inject constructor(
targetSdk.convention(defaults.targetSdk)
compileSdk.convention(defaults.compileSdk)
buildToolsVersion.convention(defaults.buildToolsVersion)
ndkVersion.convention(defaults.ndkVersion)
testTasksFilter.convention(defaults.testTasksFilter)
setTestDefaults(defaults.testOptions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public abstract class BaseAndroidPlugin internal constructor() : InfrastructureP
}

private fun Project.configureAndroid() = android {
// Set NDK version from env variable if exists
val requestedNdkVersion = System.getenv("ANDROID_NDK_VERSION")
if (requestedNdkVersion != null) ndkVersion = requestedNdkVersion

buildFeatures {
shaders = false
}
Expand All @@ -78,6 +74,7 @@ private fun CommonExtension.applyAndroidOptions(
) {
setCompileSdkVersion(options.compileSdk.get())
options.buildToolsVersion.ifPresent { buildToolsVersion = it }
options.ndkVersion.ifPresent { ndkVersion = it }

defaultConfig {
minSdk = options.minSdk.get()
Expand Down

0 comments on commit ec22134

Please sign in to comment.