-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change build/target SDK ver (26->28), min SDK ver (15->16), and other dependency versions. #232
base: master
Are you sure you want to change the base?
Conversation
When updating to SDK version 28, an error like this would appear in the build log: ~~~~~~ FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details ~~~~~~ Further into the log, there will be errors like this: ========== :app:checkDebugManifest :app:generateDebugBuildConfig :app:prepareLintJar :app:generateDebugResValues :app:generateDebugResources :app:processDebugGoogleServices Parsing json file: C:\Users\z\StudioProjects\carstream-android-auto\app\google-services.json AGPBI: {"kind":"error","text":"error: \u003citem\u003e inner element must either be a resource reference or empty.","sources":[{"file":"C:\\Users\\z\\.gradle\\caches\\transforms-1\\files-1.1\\aauto-sdk-v4.5.aar\\f96625b74a7b23c8dec4d8b375491929\\res\\values\\ids.xml","position":{"startLine":19,"startColumn":2,"startOffset":347,"endLine":21,"endColumn":9,"endOffset":400}}],"original":"","tool":"AAPT"} [...] C:\Users\z\StudioProjects\carstream-android-auto\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2878: error: <item> inner element must either be a resource reference or empty. [...] :app:mergeDebugResources Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details :app:mergeDebugResources FAILED ========== This commit overrides the errant <item> elements to provide a definition that the newer build system is happy with. This solution is based off of the following Stack Overflow answer: https://stackoverflow.com/a/53332571
When updating to SDK version 28, an error like this would appear in the build log: ~~~~~~ :app:checkDebugManifest :app:generateDebugBuildConfig :app:prepareLintJar UP-TO-DATE :app:generateDebugResValues :app:generateDebugResources :app:processDebugGoogleServices Parsing json file: C:\Users\z\StudioProjects\carstream-android-auto\app\google-services.json AGPBI: {"kind":"error","text":"error: unescaped apostrophe in string","sources":[{"file":"C:\\Users\\z\\StudioProjects\\carstream-android-auto\\app\\src\\main\\res\\values-it\\strings.xml","position":{"startLine":27,"startColumn":4,"startOffset":1761,"endColumn":72,"endOffset":1829}}],"original":"","tool":"AAPT"} AGPBI: {"kind":"error","text":"error: not a valid string.","sources":[{"file":"C:\\Users\\z\\StudioProjects\\carstream-android-auto\\app\\src\\main\\res\\values-it\\strings.xml","position":{"startLine":27,"startColumn":4,"startOffset":1761,"endColumn":72,"endOffset":1829}}],"original":"","tool":"AAPT"} C:\Users\z\StudioProjects\carstream-android-auto\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-it\values-it.xml:89: error: unescaped apostrophe in string C:\Users\z\StudioProjects\carstream-android-auto\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-it\values-it.xml:89: error: not a valid string. :app:mergeDebugResources Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details :app:mergeDebugResources FAILED FAILURE: Build failed with an exception. ~~~~~~ This commit resolves the issue by adding the necessary escaping backslash before the apostrophes in the offending strings.
It was probably a red herring and not related to the crash I was experiencing, but getting rid of it is a good idea because this will aid in process of elimination.
Set dexOptions.jumboMode = true; to mitigate an exception that might be encountered when trying to generate a (signed?) APK: "com.android.dex.DexException: Cannot merge new index 65536 into a non-jumbo instruction!" Solution was taken from this stack overflow article: https://stackoverflow.com/questions/26093664/dexexception-cannot-merge-new-index-65536-into-a-non-jumbo-instruction
When updating to SDK version 28, an error like this would appear in the build log: ~~~~~~ :app:generateDebugResources :app:processDebugGoogleServices Parsing json file: C:\Users\z\StudioProjects\carstream-android-auto\app\google-services.json :app:mergeDebugResources :app:createDebugCompatibleScreenManifests :app:processDebugManifest :app:splitsDiscoveryTaskDebug AGPBI: {"kind":"error","text":"error: resource string/receive_from_phone (aka com.google.android.kk:string/receive_from_phone) not found.","sources":[{"file":"C:\\Users\\z\\StudioProjects\\carstream-android-auto\\app\\src\\main\\res\\layout\\fragment_webview_car.xml","position":{"startLine":138}}],"original":"","tool":"AAPT"} C:\Users\z\StudioProjects\carstream-android-auto\app\src\main\res\layout\fragment_webview_car.xml:139: error: resource string/receive_from_phone (aka com.google.android.kk:string/receive_from_phone) not found. error: failed linking file resources. ~~~~~~ This commit resolves the issue by adding a receive_from_phone entry in the values/strings.xml file with the value "Receive from phone". I am not sure if this is what that value would have originally expanded to. The string is referred to by fragment_webview_car (as shown in the error), but the (English) definition for the string appears nowhere in the project. Perhaps this is from an older version of some API and is no longer available due to the update. At the time of this writing, there is a definition in values-ro/strings.xml which expands to "Primire" (and I don't know what that means). I tried to search for clues on the internets about where this might be defined and how to cope with the loss, but this might have been too obscure or specific to get any good leads. String identifiers are usually pretty true to their English expansion, so "Receive from phone" it is.
When updating to SDK version 28, an error like this would appear in the build log: ~~~~~~ C:\Users\z\StudioProjects\carstream-android-auto\app\src\main\res\values-ro\strings.xml:14: Error: "send_to_car" is translated here but not found in default locale [ExtraTranslation] <string name="send_to_car">Trimitere la masina</string> ~~~~~~~~~~~~~~~~~~ Explanation for issues of type "ExtraTranslation": If a string appears in a specific language translation file, but there is no corresponding string in the default locale, then this string is probably unused. (It's technically possible that your application is only intended to run in a specific locale, but it's still a good idea to provide a fallback.). Note that these strings can lead to crashes if the string is looked up on any locale not providing a translation, so it's important to clean them up. ~~~~~~ This commit resolves the issue by adding a send_to_car entry in the values/strings.xml file with the value "Send to car". This might be similar in nature to the "receive_from_phone", just different in that the string isn't explicitly referenced in the project. I don't like the idea of potential crashes, so I'm putting a defualt value in English and hoping that its identifier is representative of what it's supposed to expand to.
okio is a dependency of okhttp3. Presumably, it wasn't necessary for this dependency to be specified in the earlier Android SDK version (not needed on 26, maybe needed on 28), or perhaps this was pulled by a newer version of okhttp3 (not needed for okhttp3-3.9.1, maybed needed for okhttp3-4.0.0-alpha01). At any rate, this commit prepares the codebase for such version bumps. I believe I encountered this as a runtime crash, though this problem, by its nature, could be encountered at build time depending on configuration: https://talk.remobjects.com/t/build-error-when-including-com-squareup-okio-jar/18249 The error message encountered was something like this: java.lang.ClassNotFoundException: Didn't find class "okio.Buffer" (It was longer, but I can't be more specific because I no longer have the log for it.)
When updating to SDK version 28, an error like this would appear in the build log: ~~~~~~ :app:compileDebugSources :app:mergeDebugShaders :app:compileDebugShaders :app:generateDebugAssets :app:mergeDebugAssets :app:transformClassesWithRealmTransformerForDebug com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\z\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp3\okhttp\4.0.0-alpha01\5d58cd3772c4a977ab105b07d5698091ee5e6834\okhttp-4.0.0-alpha01.jar at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [...] Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\z\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp3\okhttp\4.0.0-alpha01\5d58cd3772c4a977ab105b07d5698091ee5e6834\okhttp-4.0.0-alpha01.jar at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:550) at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$1(DexArchiveBuilderTransform.java:488) at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424) [...] Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing okhttp3/internal/ws/RealWebSocket.class The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 26 or above. at com.android.builder.dexing.DxDexArchiveBuilder.getExceptionToRethrow(DxDexArchiveBuilder.java:143) at com.android.builder.dexing.DxDexArchiveBuilder.convert(DxDexArchiveBuilder.java:89) at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:545) ... 6 more Caused by: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26) at com.android.dx.cf.code.Simulator$SimVisitor.visitConstant(Simulator.java:711) at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:781) at com.android.dx.cf.code.Simulator.simulate(Simulator.java:103) [...] :app:transformClassesWithDexBuilderForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\z\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp3\okhttp\4.0.0-alpha01\5d58cd3772c4a977ab105b07d5698091ee5e6834\okhttp-4.0.0-alpha01.jar [...] ~~~~~~ This commit is a workaround that sets compileOptions.sourceCompatibility and compileOptions.targetCompatibility as suggested by the build system's error message.
This might not update everything, but it does get to a working configuration on SDK/platform v28. This will bump the minSdkVersion from 15 to 16. According to https://developer.android.com/about/dashboards/index.html this will make CarStream no longer work on Android 4.0.4 and earlier devices. 4.1.x and later should still work. This represents about 0.6% of the active devices in the last 7 days (0.3% for the 4.0 family plus 0.3% for the 2.3 family). One of those is probably mine, and I can't imagine actually wanting to use the thing to connect to Android Auto; maps would be sooooo slow, assuming any of it would work at all.
@chadjoan Can you please update the .travis.yml too to 28.0.3. Without that travis is not able to build. |
The compileOptions section of build.gradle ended up outside of the 'android' toplevel section, which caused CI tests to fail. I've moved it back into the 'android' section and tried to line it up with what PR#232 has so that future merge should be fine at this spot.
c4b6364
to
34ee553
Compare
I tried. The error mentioning missing licenses is gone now. But... The Travis script is now producing AAPT errors about the " inner element", which should have already been fixed by the commit that created the override_id_bodies.xml file. However, in this case the error message is slightly different. It is mentioning aauto-sdk-v4.5 specifically instead of just some generic project directory for merging machine generated text/code. I followed the parent commits from the commit that Travis CI tested to confirm that my earlier fix for this type of error message is still present in the codebase. And it is. So I don't think it's a problem with Travis CI building the wrong code/commit. Prompted by the error message and noticing that build.gradle has a line "compile 'com.github.martoreto:aauto-sdk:v4.5'" in it, I went to https://github.com/martoreto/aauto-sdk to look at the res/values/ids.xml file to see what things I might need to add to override_id_bodies.xml (the error message in the Travis output seems to lack this information, unfortunately). Well, apparently that project was taken down, and a message was left: "This was an unofficial SDK for Android Auto. ... Google asked me to take it down, citing the resulting abuse." So I'm not really sure how this works in the first place: CarStream appears to depend on something that no longer exists. Google searching aauto-sdk (along with other terms that I forget now) brought me to bluenazgul/aauto-sdk on github. This one does seem to be populated with code, but I have no idea if this is an accurate representation of what Travis CI is trying to integrate with. I suspect that it is different, actually: instead of res/values/idx.xml it has res-extra/values/ids.xml (note the "-extra" after "res") and the contents of that file seem like they would be perfectly compatible with the newer version of the build system. I can't reproduce the error on my system. Given that I can't repro Travis CI's new error, and the error messages lack the identifiers that I would need for implementing the typical workaround, I am not sure how to proceed at the moment. Let me know if you have any ideas. In case it helps, here are a few things I could use help with:
It seems like you've been away from this project for a long time, so thank you for responding to my pull requests! And, of course, for writing this app in the first place :) |
How about cloning one of the repos from https://github.com/martoreto/aauto-sdk/network/members and then making changes to it and adding that as a dependency ? |
Good idea. I'll try that when I get back to working on this. I didn't know about that view in github. That's pretty handy. |
Update: I'm having issues getting aauto-sdk to build as a submodule. I made a Stack Overflow question in the hopes that someone more experienced with Gradle can help: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😀
This PR is the followup to pull request #229 : "Prep work for updates of SDK (v26->v28) and other dependencies". It also follows chronologically after my other pull requests #230 : 'Solve "leaked Intent" exception.' and #231 : "Fix for APK gen exception: com.android.dex.DexException". Please merge those first to avoid merge conflicts, build errors, and other potential problems (or perhaps just merge this to pull all changes and ignore+close the others if you don't need the metadata).
Notable caveat from the commit message:
Hope this helps.
Thank you for making this app!