Skip to content

Commit

Permalink
Merge pull request #238 from bugsnag/v5-optimize-ndk-splits
Browse files Browse the repository at this point in the history
Avoid unnecessary SO mapping file uploads for ABI splits
  • Loading branch information
fractalwrench authored Jul 22, 2020
2 parents f465018 + 880f2d3 commit c896506
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 5.0.0 (TBD)

Avoid unnecessary SO mapping file uploads for ABI splits
[#238](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/238)

Alter bugsnag extension to allow multiple shared object paths
[#237](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/237)

Expand Down
59 changes: 59 additions & 0 deletions features/agp3-features/ndk_app.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,62 @@ Scenario: Custom objdump location
And the payload field "arch" equals "x86_64" for request 2

And the request 3 is valid for the Build API

Scenario: NDK app only uploads SO file matching architecture for ABI splits
When I set environment variable "ABI_SPLITS" to "enabled"
When I build the NDK app
Then I should receive 18 requests

And the request 0 is valid for the Android Mapping API
And the payload field "versionCode" equals "5" for request 0

And the request 1 is valid for the Android Mapping API
And the payload field "versionCode" equals "4" for request 1

And the request 2 is valid for the Android Mapping API
And the payload field "versionCode" equals "1" for request 2

And the request 3 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 3

And the request 4 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 4

And the request 5 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 5

And the request 6 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 6

And the request 7 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 7

And the request 8 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 8

And the request 9 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 9

And the request 10 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 10

And the request 11 is valid for the Android Mapping API
And the payload field "versionCode" equals "3" for request 11

And the request 12 is valid for the Android Mapping API
And the payload field "versionCode" equals "2" for request 12

And the request 13 is valid for the Build API
And the payload field "appVersionCode" equals "5" for request 13

And the request 14 is valid for the Build API
And the payload field "appVersionCode" equals "4" for request 14

And the request 15 is valid for the Build API
And the payload field "appVersionCode" equals "1" for request 15

And the request 16 is valid for the Build API
And the payload field "appVersionCode" equals "3" for request 16

And the request 17 is valid for the Build API
And the payload field "appVersionCode" equals "2" for request 17
83 changes: 83 additions & 0 deletions features/agp4-features/ndk_app.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,86 @@ Scenario: Custom objdump location
And the payload field "arch" equals "x86_64" for request 4

And the request 5 is valid for the Build API

Scenario: NDK app only uploads SO file matching architecture for ABI splits
When I set environment variable "ABI_SPLITS" to "enabled"
When I build the NDK app
Then I should receive 26 requests

And the request 0 is valid for the Android Mapping API
And the payload field "versionCode" equals "5" for request 0

And the request 1 is valid for the Android Mapping API
And the payload field "versionCode" equals "4" for request 1

And the request 2 is valid for the Android Mapping API
And the payload field "versionCode" equals "1" for request 2

And the request 3 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 3

And the request 4 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 4

And the request 5 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 5

And the request 6 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 6

And the request 7 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 7

And the request 8 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 8

And the request 9 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 9

And the request 10 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 10

And the request 11 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 11

And the request 12 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86" for request 12

And the request 13 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 13

And the request 14 is valid for the Android NDK Mapping API
And the payload field "arch" equals "x86_64" for request 14

And the request 15 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 15

And the request 16 is valid for the Android NDK Mapping API
And the payload field "arch" equals "armeabi-v7a" for request 16

And the request 17 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 17

And the request 18 is valid for the Android NDK Mapping API
And the payload field "arch" equals "arm64-v8a" for request 18

And the request 19 is valid for the Android Mapping API
And the payload field "versionCode" equals "3" for request 19

And the request 20 is valid for the Android Mapping API
And the payload field "versionCode" equals "2" for request 20

And the request 21 is valid for the Build API
And the payload field "appVersionCode" equals "5" for request 21

And the request 22 is valid for the Build API
And the payload field "appVersionCode" equals "4" for request 22

And the request 23 is valid for the Build API
And the payload field "appVersionCode" equals "1" for request 23

And the request 24 is valid for the Build API
And the payload field "appVersionCode" equals "3" for request 24

And the request 25 is valid for the Build API
And the payload field "appVersionCode" equals "2" for request 25
24 changes: 24 additions & 0 deletions features/fixtures/ndkapp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.application'

ext.abiCodes = ['arm64-v8a':2, 'armeabi-v7a':3, 'x86':4, 'x86_64':5]

android {
compileSdkVersion 29
ndkVersion "16.1.4479499"
Expand Down Expand Up @@ -33,6 +35,28 @@ android {
lintOptions {
checkReleaseBuilds false
}

if ("enabled" == System.env.ABI_SPLITS) {
splits {
abi {
reset()
enable true
universalApk true
include 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
}
}

applicationVariants.all { variant ->
variant.outputs.each { output ->
def abiVersionCode =
project.ext.abiCodes.get(output.getFilter("ABI"))

if (abiVersionCode != null) {
output.versionCodeOverride = abiVersionCode
}
}
}
}
}

dependencies {
Expand Down
23 changes: 23 additions & 0 deletions features/fixtures/ndkapp_agp340/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.application'

ext.abiCodes = ['arm64-v8a':2, 'armeabi-v7a':3, 'x86':4, 'x86_64':5]

android {
compileSdkVersion 29

Expand Down Expand Up @@ -32,6 +34,27 @@ android {
lintOptions {
checkReleaseBuilds false
}
if ("enabled" == System.env.ABI_SPLITS) {
splits {
abi {
reset()
enable true
universalApk true
include 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
}
}

applicationVariants.all { variant ->
variant.outputs.each { output ->
def abiVersionCode =
project.ext.abiCodes.get(output.getFilter("ABI"))

if (abiVersionCode != null) {
output.versionCodeOverride = abiVersionCode
}
}
}
}
}

dependencies {
Expand Down
9 changes: 1 addition & 8 deletions src/main/kotlin/com.bugsnag.android.gradle/Abi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ enum class Abi(val abiName: String, val toolchainPrefix: String, val objdumpPref
);

companion object {
fun findByName(abiName: String): Abi? {
for (value in values()) {
if (value.abiName == abiName) {
return value
}
}
return null
}
fun findByName(abiName: String) = values().firstOrNull { it.abiName == abiName }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AndroidManifestParser {

@Throws(ParserConfigurationException::class, SAXException::class, IOException::class)
fun readManifest(manifestPath: File, logger: Logger): AndroidManifestInfo {
logger.debug("Reading manifest at: \${manifestPath}")
logger.debug("Reading manifest at: ${manifestPath}")
val root = XmlParser().parse(manifestPath)
val application = (root[TAG_APPLICATION] as NodeList)[0] as Node
val metadataTags = findMetadataTags(application)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ open class BugsnagManifestUuidTask @Inject constructor(objects: ObjectFactory) :
private fun addManifestPath(manifestPaths: MutableList<File?>, directory: File, logger: Logger, variantOutput: ApkVariantOutput) {
val manifestFile = Paths.get(directory.toString(), variantOutput.dirName, "AndroidManifest.xml").toFile()
if (manifestFile.exists()) {
logger.info("Found manifest at \${manifestFile}")
logger.info("Found manifest at ${manifestFile}")
manifestPaths.add(manifestFile)
} else {
logger.error("Failed to find manifest at \${manifestFile}")
logger.error("Failed to find manifest at ${manifestFile}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ class BugsnagMultiPartUploadRequest {
mpEntity.addPart("overwrite", StringBody("true"))
}
val logger = project.logger
logger.debug("apiKey: \${manifestInfo.apiKey}")
logger.debug("appId: \${applicationId}")
logger.debug("versionCode: \${manifestInfo.versionCode}")
logger.debug("buildUUID: \${manifestInfo.buildUUID}")
logger.debug("versionName: \${manifestInfo.versionName}")
logger.debug("overwrite: \${project.bugsnag.overwrite}")
logger.debug("apiKey: ${manifestInfo.apiKey}")
logger.debug("appId: ${variant.applicationId}")
logger.debug("versionCode: ${manifestInfo.versionCode}")
logger.debug("buildUUID: ${manifestInfo.buildUUID}")
logger.debug("versionName: ${manifestInfo.versionName}")
}

private fun uploadToServer(project: Project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ open class BugsnagReleasesTask @Inject constructor(
os.write(payload.toString().toByteArray(charset(CHARSET_UTF8)))
val statusCode = conn.responseCode
if (statusCode == 200) {
logger.info("Uploaded release info to Bugsnag")
logger.lifecycle("Bugsnag uploaded release info")
return true
} else {
var reader: BufferedReader? = null
Expand Down
Loading

0 comments on commit c896506

Please sign in to comment.