@@ -65,45 +65,31 @@ android {
65
65
}
66
66
}
67
67
68
+ // There is not any normal way to package native executables in an Android APK.
69
+ // It is normal to package native code as a loadable module but Android's APK
70
+ // installer will ignore files not named like a shared object, so give the
71
+ // handler executable an acceptable name
68
72
libraryVariants. all { variant ->
69
- variant. outputs. each { output ->
70
- def func = fixTrampolineFilenames(variant. baseName)
71
-
72
- tasks. findAll {
73
- it. name. startsWith(" bundleReleaseAar" )
74
- }. each {
75
- it. dependsOn func
73
+ def fixTasks = [" x86" , " x86_64" , " armeabi-v7a" , " arm64-v8a" ]. collect { arch ->
74
+ tasks. register(" fixTrampolineFilenames${ variant.baseName}${ arch} " , com.google.firebase.gradle.NdkBinaryFixTask ) {
75
+ it. inputFile =
76
+ file(" ${ buildDir} /intermediates/ndkBuild/${ variant.baseName} /obj/local/${ arch} /crashlytics-trampoline" )
76
77
}
78
+ }
77
79
78
- tasks. findAll {
79
- it. name. startsWith(" externalNativeBuild" ) && ! it. name. contains(" Clean" )
80
- }. each {
81
- func. dependsOn it
80
+ tasks. withType(com.android.build.gradle.tasks.BundleAar ) {
81
+ if (it. variantName != variant. baseName) return
82
+ fixTasks. each { fix ->
83
+ it. dependsOn fix
84
+ it. from(fix. map { it. outputFile }) {
85
+ into fix. map { it. into }
86
+ }
82
87
}
83
88
}
84
- }
85
- }
86
-
87
-
88
- import java.nio.file.Files
89
- import java.nio.file.StandardCopyOption
90
-
91
- // There is not any normal way to package native executables in an Android APK.
92
- // It is normal to package native code as a loadable module but Android's APK
93
- // installer will ignore files not named like a shared object, so give the
94
- // handler executable an acceptable name
95
- def fixTrampolineFilenames (variantBaseName ) {
96
- project. task(" fixTrampolineFilenames${ variantBaseName} " ). configure({
97
- }). doFirst {
98
- [" x86" , " x86_64" , " armeabi-v7a" , " arm64-v8a" ]. each { arch ->
99
- def initial = new File (
100
- " ${ buildDir} /intermediates/ndkBuild/${ variantBaseName} /obj/local/${ arch} /crashlytics-trampoline" )
101
- def renamed = new File (
102
- " ${ buildDir} /intermediates/ndkBuild/${ variantBaseName} /obj/local/${ arch} /libcrashlytics-trampoline.so" )
103
-
104
- // There is no need to delete the original file, it will not be
105
- // packaged into the APK
106
- Files . copy(initial. toPath(), renamed. toPath(), StandardCopyOption . REPLACE_EXISTING )
89
+ tasks. findAll {
90
+ it. name. startsWith(" externalNativeBuild" ) && ! it. name. contains(" Clean" )
91
+ }. each { task ->
92
+ fixTasks. each { fix -> fix. configure { it. dependsOn task } }
107
93
}
108
94
}
109
95
}
0 commit comments