Skip to content

Commit

Permalink
feat: reduce aar size by removing R.class and BuildConfig.class (#5644)
Browse files Browse the repository at this point in the history
see https://www.mobileit.cz/Blog/Pages/r-class.aspx

In case a plugin needs these, they can still be enabled with `generateBuildConfig` and `generateR` properties.

Co-authored-by: Igor Randjelovic <[email protected]>
  • Loading branch information
farfromrefug and rigor789 authored Mar 7, 2022
1 parent 1435eef commit 9ad80bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion vendor/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,26 @@ task addDependenciesFromNativeScriptPlugins {

project.dependencies.add("implementation", jarFiles)
}
}
}

afterEvaluate {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
generateReleaseBuildConfig.enabled = generateBuildConfig
generateDebugBuildConfig.enabled = generateBuildConfig
generateReleaseResValues.enabled = generateR
generateDebugResValues.enabled = generateR
}

tasks.whenTaskAdded({ DefaultTask currentTask ->
if (currentTask.name == 'bundleRelease' || currentTask.name == 'bundleDebug') {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
if (!generateBuildConfig) {
currentTask.exclude '**/BuildConfig.class'
}
if (!generateR) {
currentTask.exclude '**/R.class', '**/R$*.class'
}
}
})
3 changes: 3 additions & 0 deletions vendor/gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ org.gradle.jvmargs=-Xmx16384M

android.enableJetifier=true
android.useAndroidX=true
android.nonTransitiveRClass=true
android.namespacedRClass=true
android.enableSeparateRClassCompilation=true

0 comments on commit 9ad80bf

Please sign in to comment.