Improve how aapt output is parsed in one place
While trying to build a newer version of Linphone on my own build infrastructure, I ran into this error:
... INFO: Successfully built version 4.0.1 of org.linphone ERROR: Could not build app org.linphone: Wrong package ID - build 9 but expected org.linphone
After a bit of poking around, I discovered that the regex being used to parse the output of
aapt was incorrectly for newer versions of the SDK, because a new field was added:
[email protected]:~/data/build/org.linphone$ /home/fdroid/android-sdk/build-tools/28.0.0/aapt dump badging bin/outputs/apk/release/org.linphone-release-unsigned.apk | grep package package: name='org.linphone' versionCode='4002' versionName='4.0.1' compileSdkVersion='28' compileSdkVersionCodename='9' [email protected]:~/data/build/org.linphone$ /home/fdroid/android-sdk/build-tools/27.0.3/aapt dump badging bin/outputs/apk/release/org.linphone-release-unsigned.apk | grep package package: name='org.linphone' versionCode='4002' versionName='4.0.1' platformBuildVersionName=''
.*name='([a-zA-Z0-9._]*)'.* (the regular expression in question) returns
org.linphone for the 27.0.3 output, but
9 for the 28.0.0 output, presumably due to the new
compileSdkVersionCodename field in the aapt output. This change parses that line slightly better, in order to fix this problem and hopefully avoiding similar problems in the future.