Skip to content

Commit 5408086

Browse files
charlesoj6205claude
andcommitted
Update the Shapes app build for approov-service-httpsurlconn 3.5.4
Service layer 3.5.4 needs minSdk 23 and core library desugaring. The Shapes app used minSdk 21 and Android Gradle plugin 7.1.1, so the guide dependency failed in the manifest merge, and D8 crashed on the 3.5.4 jar. - Upgrade Android Gradle plugin 7.1.1 -> 8.9.0 and Gradle 7.2 -> 8.11.1. - Add namespace and remove the manifest package attribute. - Raise minSdk 21 -> 23, compileSdk 31 -> 35 and targetSdk 31 -> 34. targetSdk 34 passes the lint check for release builds and keeps the layout unchanged, because targetSdk 35 enforces edge-to-edge. - Enable core library desugaring with desugar_jdk_libs 2.1.4. - Add R8 -dontwarn rules for the optional Google Play services and Play Integrity classes that the Approov SDK refers to. - Document minSdk 23, desugaring, the R8 rules and the Android Studio and JDK requirements in README.md and SHAPES-EXAMPLE.md. Tested: debug and release builds pass, with and without the guide dependency. On an Android 17 emulator, the app initialized SDK 3.5.3 and fetched a token for the v3 endpoint. Refs approov/core-project-approov#644 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8ebe28b commit 5408086

7 files changed

Lines changed: 46 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ The `Maven` repository is already present in the gradle.build file so the only i
1414
implementation("io.approov:service.httpsurlconn:3.5.4")
1515
```
1616

17+
The service layer requires [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) and a minimum SDK version of 23. Add the following to the app-level `build.gradle` file:
18+
19+
```
20+
android {
21+
defaultConfig {
22+
minSdkVersion 23
23+
}
24+
compileOptions {
25+
coreLibraryDesugaringEnabled true
26+
}
27+
}
28+
29+
dependencies {
30+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
31+
}
32+
```
33+
34+
Use Android Gradle plugin 8.x or later. With Android Gradle plugin 7.x, the build fails in D8 with a `NullPointerException` while it processes the service layer. With Android Gradle plugin 8.x and no desugaring, the build fails with `Dependency 'io.approov:service.httpsurlconn:3.5.4' requires core library desugaring to be enabled`.
35+
36+
If your release build uses R8 (`minifyEnabled true`), add these rules to your ProGuard rules file. The Approov SDK refers to optional Google Play services and Play Integrity classes, and Android Gradle plugin 8 stops the build with `Missing class` errors if they are not present:
37+
38+
```
39+
-dontwarn com.google.android.gms.tasks.**
40+
-dontwarn com.google.android.play.core.integrity.**
41+
```
42+
1743
Make sure you do a Gradle sync (by selecting `Sync Now` in the banner at the top of the modified `.gradle` file) after making these changes.
1844

1945
This package is actually an open source wrapper layer that allows you to easily use Approov with `HttpsUrlConnection`. This has a further dependency to the closed source [Approov SDK](https://central.sonatype.com/artifact/io.approov/approov-android-sdk).
@@ -26,7 +52,7 @@ The following app permissions need to be available in the manifest to use Approo
2652
<uses-permission android:name="android.permission.INTERNET" />
2753
```
2854

29-
Note that the minimum SDK version you can use with the Approov package is 21 (Android 5.0).
55+
Note that the minimum SDK version you can use with the Approov package is 23 (Android 6.0).
3056

3157
Please [read this](https://approov.io/docs/latest/approov-usage-documentation/#targeting-android-11-and-above) section of the reference documentation if targeting Android 11 (API level 30) or above.
3258

‎SHAPES-EXAMPLE.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This quickstart is written specifically for native Android apps that are written
55
## WHAT YOU WILL NEED
66
* Access to a trial or paid Approov account
77
* The `approov` command line tool [installed](https://approov.io/docs/latest/approov-installation/) with access to your account
8-
* [Android Studio](https://developer.android.com/studio) installed (Android Studio Bumblebee 2021.1.1 is used in this guide)
8+
* [Android Studio](https://developer.android.com/studio) installed, in a version that supports Android Gradle plugin 8.9 (see the [compatibility table](https://developer.android.com/build/releases/gradle-plugin#android_gradle_plugin_and_android_studio_compatibility)). The Shapes app uses Android Gradle plugin 8.9.0 and Gradle 8.11.1, which require JDK 17.
99
* The contents of this repo
1010

1111
## RUNNING THE SHAPES APP WITHOUT APPROOV
@@ -48,6 +48,8 @@ The `approov-service-httpsurlconn` dependency needs to be added as follows to th
4848
implementation("io.approov:service.httpsurlconn:3.5.4")
4949
```
5050

51+
The service layer requires [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) and a minimum SDK version of 23. The Shapes app already sets `minSdkVersion 23`, `coreLibraryDesugaringEnabled true` and the `coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'` dependency in `app/build.gradle`, so no other change is necessary. If you add Approov to your own app, see [ADDING APPROOV SERVICE DEPENDENCY](README.md#adding-approov-service-dependency).
52+
5153
Make sure you do a Gradle sync (by selecting `Sync Now` in the banner at the top of the modified `.gradle` file) after making these changes.
5254

5355
Note that `approov-service-httpsurlconn` is actually an open source wrapper layer that allows you to easily use Approov with `HttpsUrlConnection`. This has a further dependency to the closed source Approov SDK itself.

‎shapes-app/app/build.gradle‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 31
4+
namespace "io.approov.shapes"
5+
compileSdkVersion 35
56
defaultConfig {
67
applicationId "io.approov.shapes"
7-
minSdkVersion 21
8-
targetSdkVersion 31
8+
minSdkVersion 23
9+
targetSdkVersion 34
910
versionCode 3
1011
versionName "3.0"
1112
}
@@ -27,11 +28,14 @@ android {
2728
compileOptions {
2829
sourceCompatibility JavaVersion.VERSION_1_8
2930
targetCompatibility JavaVersion.VERSION_1_8
31+
// Required by io.approov:service.httpsurlconn 3.5.4 and later
32+
coreLibraryDesugaringEnabled true
3033
}
3134
}
3235
}
3336

3437
dependencies {
38+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
3539
implementation fileTree(dir: 'libs', include: ['*.jar'])
3640
implementation 'androidx.appcompat:appcompat:1.4.1'
3741
}

‎shapes-app/app/proguard-rules.pro‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@
1616
# public *;
1717
#}
1818
-keep class com.criticalblue.approovsdk.** {*;}
19+
20+
# The Approov SDK refers to optional Google Play services and Play Integrity classes that
21+
# are not present unless the app includes those libraries. Android Gradle plugin 8 treats
22+
# missing classes as an error in R8.
23+
-dontwarn com.google.android.gms.tasks.**
24+
-dontwarn com.google.android.play.core.integrity.**

‎shapes-app/app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="io.approov.shapes">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<uses-permission android:name="android.permission.INTERNET" />
65
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

‎shapes-app/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
mavenCentral()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:7.1.1'
11+
classpath 'com.android.tools.build:gradle:8.9.0'
1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
1414
}

‎shapes-app/gradle/wrapper/gradle-wrapper.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip

0 commit comments

Comments
 (0)