AGP 4+ contains new APIs for accessing build variants (and the APKs produced for each of them), and the existing APIs have been deprecated.
The main differences appear to be:
com.android.build.gradle.api.TestVariant has been replaced by com.android.build.api.variant.AndroidTest.
- Instead of using
com.android.build.gradle.AppExtension and com.android.build.gradle.TestedExtension to access build variants, one needs to use com.android.build.api.variant.ApplicationAndroidComponentsExtension to access com.android.build.api.variant.ApplicationVariant, which has a androidTest: AndroidTest? property for the corresponding instrumentation test variant. (And com.android.build.api.variant.LibraryAndroidComponentsExtension to access com.android.build.api.variant.LibraryVariant.)
ApplicationVariant, LibraryVariant, and AndroidTest expose their outputs as com.android.build.api.variant.VariantOutputs, but there's no longer a way to get the path to each APK output via that API. Instead, one has to use the com.android.build.api.artifact.Artifacts API to access a DirectoryProperty for the folder the APKs are placed in, and use BuiltArtifactsLoader to access the outputs within a task action.
I've taken a stab at the update here, but the BuiltArtifactsLoader change is a bit tricky: master...jschear:js/agp_7
AGP 4+ contains new APIs for accessing build variants (and the APKs produced for each of them), and the existing APIs have been deprecated.
The main differences appear to be:
com.android.build.gradle.api.TestVarianthas been replaced bycom.android.build.api.variant.AndroidTest.com.android.build.gradle.AppExtensionandcom.android.build.gradle.TestedExtensionto access build variants, one needs to usecom.android.build.api.variant.ApplicationAndroidComponentsExtensionto accesscom.android.build.api.variant.ApplicationVariant, which has aandroidTest: AndroidTest?property for the corresponding instrumentation test variant. (Andcom.android.build.api.variant.LibraryAndroidComponentsExtensionto accesscom.android.build.api.variant.LibraryVariant.)ApplicationVariant,LibraryVariant, andAndroidTestexpose their outputs ascom.android.build.api.variant.VariantOutputs, but there's no longer a way to get the path to each APK output via that API. Instead, one has to use thecom.android.build.api.artifact.ArtifactsAPI to access aDirectoryPropertyfor the folder the APKs are placed in, and useBuiltArtifactsLoaderto access the outputs within a task action.I've taken a stab at the update here, but the
BuiltArtifactsLoaderchange is a bit tricky: master...jschear:js/agp_7