Skip to content

Commit

Permalink
fix: add consumer proguard rules; update kotlin & gradle; lint (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori authored Aug 16, 2024
1 parent 1044972 commit cb1699c
Show file tree
Hide file tree
Showing 69 changed files with 1,995 additions and 1,628 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'zulu'

- name: Cache Gradle Dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'zulu'

- name: Lint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'zulu'

- name: Set up Node
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'zulu'

- name: Cache Gradle Dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/captures
.externalNativeBuild
.cxx
.kotlin
6 changes: 5 additions & 1 deletion analytics-connector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {

defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 33
versionName PUBLISH_VERSION
}

Expand All @@ -33,6 +33,10 @@ android {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.amplitude.analytics.connector'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions analytics-connector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amplitude.analytics">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'org.jetbrains.dokka'
apply plugin: 'org.jlleitschuh.gradle.ktlint'

buildscript {
ext.kotlin_version = '1.6.21'
ext.kotlin_version = '1.8.22'
ext.dokka_version = '1.4.32'

repositories {
Expand All @@ -15,11 +15,11 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'com.android.tools.build:gradle:8.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
classpath "org.jlleitschuh.gradle:ktlint-gradle:12.1.1"

}
}
Expand Down
26 changes: 13 additions & 13 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
compileSdkVersion 34

defaultConfig {
applicationId "com.amplitude.exampleapp"
minSdkVersion 17
targetSdkVersion 30
minSdkVersion 19
targetSdkVersion 34
versionCode 1
versionName "1.0"

Expand All @@ -21,13 +21,14 @@ android {
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
kotlinOptions {
jvmTarget = '17'
}
namespace 'com.amplitude.exampleapp'
}

dependencies {
Expand All @@ -39,11 +40,10 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.amplitude:android-sdk:2.30.0'
// implementation("com.amplitude:experiment-android-client:0.0.4")
implementation 'com.amplitude:android-sdk:2.39.8'
implementation project(path: ':sdk')
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

This file was deleted.

6 changes: 3 additions & 3 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amplitude.exampleapp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".ExampleApplication"
Expand All @@ -13,7 +12,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import android.app.Application;

import com.amplitude.api.Amplitude;
import com.amplitude.api.AmplitudeAnalyticsProvider;
import com.amplitude.api.AmplitudeClient;
import com.amplitude.api.AmplitudeUserProvider;
import com.amplitude.experiment.Experiment;
import com.amplitude.experiment.ExperimentClient;
import com.amplitude.experiment.ExperimentConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Bundle;
import android.widget.TextView;

import com.amplitude.experiment.Experiment;
import com.amplitude.experiment.ExperimentClient;
import com.amplitude.experiment.Variant;
import com.google.android.material.bottomnavigation.BottomNavigationView;
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=amplitude
POM_DEVELOPER_NAME=Amplitude
POM_DEVELOPER_EMAIL=[email protected]
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
8 changes: 6 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 33
versionName PUBLISH_VERSION
buildConfigField "String", "VERSION_NAME", "\"$PUBLISH_VERSION\""
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -37,6 +37,10 @@ android {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.amplitude.experiment'
}

dependencies {
Expand All @@ -47,7 +51,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20201115'
testImplementation 'org.json:json:20240303'
testImplementation project(path: ':sdk')
testImplementation "io.mockk:mockk:1.12.0"
}
Expand Down
35 changes: 35 additions & 0 deletions sdk/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

# Don't print notes about potential mistakes or omissions in the configuration for kotlinx-serialization classes
# See also https://github.com/Kotlin/kotlinx.serialization/issues/1900
-dontnote kotlinx.serialization.**

# Serialization core uses `java.lang.ClassValue` for caching inside these specified classes.
# If there is no `java.lang.ClassValue` (for example, in Android), then R8/ProGuard will print a warning.
# However, since in this case they will not be used, we can disable these warnings
-dontwarn kotlinx.serialization.internal.ClassValueReferences
3 changes: 1 addition & 2 deletions sdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amplitude.experiment">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import org.json.JSONObject
*/
@Deprecated(
"Update your version of the amplitude analytics SDK to 2.36.0+ and for seamless " +
"integration with the amplitude analytics SDK"
"integration with the amplitude analytics SDK",
)
class AmplitudeAnalyticsProvider(
private val amplitudeClient: AmplitudeClient,
) : ExperimentAnalyticsProvider {

override fun track(event: ExperimentAnalyticsEvent) {
amplitudeClient.logEvent(event.name, JSONObject(event.properties))
}
Expand Down
19 changes: 10 additions & 9 deletions sdk/src/main/java/com/amplitude/api/AmplitudeUserProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import java.util.Locale

@Deprecated(
"Update your version of the amplitude analytics SDK to 2.36.0+ and for seamless " +
"integration with the amplitude analytics SDK"
"integration with the amplitude analytics SDK",
)
class AmplitudeUserProvider(private val amplitudeClient: AmplitudeClient) : ExperimentUserProvider {

private var initialized = false
private var version: String? = null
private var carrier: String? = null
Expand All @@ -39,18 +38,19 @@ class AmplitudeUserProvider(private val amplitudeClient: AmplitudeClient) : Expe
Logger.d(
String.format(
"Waited %.3f ms for Amplitude SDK initialization",
(end - start) / 1000000.0
)
(end - start) / 1000000.0,
),
)
}

private fun cacheVersion() {
if (amplitudeClient.context != null) {
val packageInfo: PackageInfo
try {
packageInfo = amplitudeClient.context.packageManager.getPackageInfo(
amplitudeClient.context.packageName, 0
)
packageInfo =
amplitudeClient.context.packageManager.getPackageInfo(
amplitudeClient.context.packageName, 0,
)
version = packageInfo.versionName
} catch (ignored: PackageManager.NameNotFoundException) {
} catch (ignored: Exception) {
Expand All @@ -61,8 +61,9 @@ class AmplitudeUserProvider(private val amplitudeClient: AmplitudeClient) : Expe
private fun cacheCarrier() {
if (amplitudeClient.context != null) {
try {
val manager = amplitudeClient.context
.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val manager =
amplitudeClient.context
.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
carrier = manager.networkOperatorName
} catch (e: Exception) {
// Failed to get network operator name from network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import kotlinx.serialization.Serializable
internal data class EvaluationBucket(
// How to select the prop from the context.
val selector: List<String>,

// A random string used to salt the bucketing value prior to hashing.
val salt: String,

// Determines which variant, if any, should be returned based on the
// result of the hash functions.
val allocations: List<EvaluationAllocation>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import kotlinx.serialization.Serializable
internal data class EvaluationCondition(
// How to select the property from the evaluation state.
val selector: List<String>,

// The operator.
val op: String,

// The values to compare to.
val values: Set<String>
val values: Set<String>,
)
Loading

0 comments on commit cb1699c

Please sign in to comment.