Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added --classpath_entry for Desugar (#2158)
Fixes: #2143 Context: #1639 Xamarin.Android's current implementation of desugar runs a command such as: java -jar desugar_deploy.jar --bootclasspath_entry ~\android-toolchain\sdk\platforms\android-28\android.jar --min_sdk_version 11 --classpath_entry xamarin-android\bin\Debug\lib\xamarin.android\xbuild-frameworks\MonoAndroid\v9.0\mono.android.jar --input Lambda.jar --output obj\Debug\android\bin\desugared\14-57-25-90-94-EE-16-09-B8-68-88-BC-9D-FC-6C-89Lambda.jar However, certain jars are failing with messages such as: Exception in thread "main" java.lang.TypeNotPresentException: Type okhttp3.Interceptor not present Or another example: Error: java.lang.TypeNotPresentException : Type io.reactivex.functions.Action not present The first fix here is to add the `--classpath_entry` flag for every `--input`, for some reason `Desugar` is not treating `--input` jars as classpath entries? Next, we expanded on the `BuildTest.Desugar` test using a complicated set of Java libraries from Maven central: proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okio-1.13.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okhttp-3.8.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/okhttp3/okhttp/3.8.0/okhttp-3.8.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "retrofit-2.3.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/retrofit/2.3.0/retrofit-2.3.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "converter-gson-2.3.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/converter-gson/2.3.0/converter-gson-2.3.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "gson-2.7.jar") { WebContent = "http://central.maven.org/maven2/com/google/code/gson/gson/2.7/gson-2.7.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidAarLibrary", "twitter-core-3.3.0.aar") { WebContent = "http://repo.spring.io/libs-release/com/twitter/sdk/android/twitter-core/3.3.0/twitter-core-3.3.0.aar", }); This was working, as long as you had `android:minSdkVersion="24"` in your `AndroidManifest.xml`. This wasn't ideal if you wanted to run your app on older API levels... Luckily, another command line switched solved this problem: //Added to the Desugar MSBuild task if (minApiVersion < 24) { cmd.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); } What a crazy name for a flag! Documented by `desugar` as: --[no]desugar_try_with_resources_omit_runtime_classes (a boolean; default: "false") Omits the runtime classes necessary to support try-with-resources from the output. This property has effect only if -- desugar_try_with_resources_if_needed is used. --min_sdk_version (an integer; default: "1") Minimum targeted sdk version. If >= 24, enables default methods in interfaces. This makes sense that something would happen at API level 24... Once doing this, the `Desugar` test passes without modifying `minSdkVersion`. The expanded `Desugar` test will also greatly help with our D8/R8 implementation (#2040). This complex set of Java dependencies from Maven will be useful.
- Loading branch information