Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.time.Duration
import com.android.build.gradle.BaseExtension

// Top-level build file where you can add configuration options common to all sub-projects/modules.

Expand All @@ -8,11 +9,11 @@ buildscript {
google()
}
dependencies {
classpath('com.android.tools.build:gradle:7.1.1')
classpath('com.android.tools.build:gradle:8.3.2')

// For displaying method/field counts when building with Gradle:
// https://github.com/KeepSafe/dexcount-gradle-plugin
classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.1.0")
classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:4.0.0")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -21,13 +22,15 @@ buildscript {

plugins {
id("java")
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}

// Must be specified in root project for the gradle nexus publish plugin.
group = "com.launchdarkly"
// Specified in the root project so Releaser's `publish-dry-run.sh` can see it in `./gradlew properties`
archivesBaseName = 'launchdarkly-android-client-sdk'
base {
// Specified in the root project so Releaser's `publish-dry-run.sh` can see it in `./gradlew properties`
archivesName = "launchdarkly-android-client-sdk"
}
// Specified in gradle.properties
version = version

Expand All @@ -41,21 +44,13 @@ allprojects {
}
}

subprojects {
afterEvaluate {
configure(android.lintOptions) {
abortOnError = false
}
configure(android.compileOptions) {
def configureAndroidModule(Project project) {
project.extensions.configure(BaseExtension) { androidExt ->
androidExt.lint { abortOnError = false }
androidExt.compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
// enable deprecation checks
options.compilerArgs << "-Xlint:deprecation"
}
}
}
}

Expand All @@ -68,3 +63,20 @@ nexusPublishing {
}
}
}

subprojects { subproject ->
plugins.withId("com.android.application") {
configureAndroidModule(subproject)
}
plugins.withId("com.android.library") {
configureAndroidModule(subproject)
}
tasks.withType(JavaCompile).configureEach {
// enable deprecation checks
options.compilerArgs += "-Xlint:deprecation"
}
tasks.withType(Test).configureEach {
// Allow EasyMock/CGLIB to use reflection on Java base classes when running on newer JDKs.
jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED"]
}
}
8 changes: 4 additions & 4 deletions contract-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ plugins {
}

android {
compileSdkVersion(30)
buildToolsVersion = "30.0.3"
namespace "com.launchdarkly.sdktest"
compileSdk = 34

defaultConfig {
applicationId = "com.launchdarkly.sdktest"
minSdkVersion(21)
targetSdkVersion(30)
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
}
Expand Down
2 changes: 2 additions & 0 deletions contract-tests/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Allow compile-time-only error-prone annotations to be stripped without breaking shrink.
-dontwarn com.google.errorprone.annotations.**
3 changes: 1 addition & 2 deletions contract-tests/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.launchdarkly.sdktest">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
9 changes: 5 additions & 4 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ plugins {
}

android {
compileSdkVersion(30)
buildToolsVersion = "30.0.3"
namespace "com.launchdarkly.example"
compileSdk = 34

defaultConfig {
applicationId = "com.launchdarkly.example"
minSdkVersion(21)
targetSdkVersion(30)
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
}

buildTypes {
release {
minifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions example/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Allow compile-time-only error-prone annotations to be stripped without breaking shrink.
-dontwarn com.google.errorprone.annotations.**
9 changes: 5 additions & 4 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.launchdarkly.example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

<application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -15,4 +16,4 @@
</activity>
</application>

</manifest>
</manifest>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jan 11 09:20:17 PST 2018
#Tue Nov 25 16:57:24 ART 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
72 changes: 47 additions & 25 deletions launchdarkly-android-client-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ group = "com.launchdarkly"
version = version

android {
compileSdkVersion(30)
buildToolsVersion = "30.0.3"
namespace "com.launchdarkly.sdk.android"
compileSdk = 34

defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
minSdk = 21
targetSdk = 34
// at some point between android gradle 3.1.0 and 4.x.x the versionName field in this dsl
// stopped generating the BuildConfig::VERSION_NAME field in the end java
// classpath. put this here to bring back that field
Expand All @@ -33,8 +33,18 @@ android {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}

packagingOptions {
exclude("META-INF/**")
buildFeatures {
buildConfig = true
}

publishing {
singleVariant("release")
}

packaging {
resources {
excludes += ["META-INF/**"]
}
}

useLibrary("android.test.runner")
Expand Down Expand Up @@ -100,45 +110,56 @@ dependencies {
androidTestImplementation("com.squareup.okhttp3:mockwebserver:${versions.okhttp}")
androidTestImplementation(project(":shared-test-code"))

androidTestImplementation("androidx.test:core:1.4.0")
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestImplementation("androidx.test:rules:1.4.0")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test:core:1.5.0")
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("org.easymock:easymock:4.3")

androidTestUtil("androidx.test:orchestrator:1.4.1")
androidTestUtil("androidx.test:orchestrator:1.4.2")
}

task javadoc(type: Javadoc) {
def androidJavadoc = tasks.register("javadoc", Javadoc) {
// Include SDK sources
source android.sourceSets.main.java.srcDirs
// Include common library sources
source configurations.commonDoc.collect { zipTree(it) }
source "$buildDir/generated/source"
// Ensure generated BuildConfig is present before javadoc runs.
dependsOn("generateDebugBuildConfig", "generateReleaseBuildConfig")

include("**/*.java")

// Include classpaths for dependencies
afterEvaluate {
if (options instanceof StandardJavadocDocletOptions) {
options.source = "8"
}

doFirst {
// Include classpaths for dependencies
classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompileProvider.get().classpath.files
})
// Add Android boot classpath for references to Android OS classes.
def bootClasspath = files(android.bootClasspath)
classpath += bootClasspath
if (options instanceof StandardJavadocDocletOptions) {
options.bootClasspath = bootClasspath.files.toList()
}
}
// Include classpath for commonClasses configuration so Javadoc won't complain about java-sdk-common classes that
// internally reference Jackson, which we don't use directly
classpath += project.files(configurations.commonClasses.resolve())
// Add Android boot classpath for references to Android OS classes.
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task sourcesJar(type: Jar) {
classifier = "sources"
def sourcesJar = tasks.register("sourcesJar", Jar) {
archiveClassifier.set("sources")
from android.sourceSets.main.java.srcDirs
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = "javadoc"
from javadoc.destinationDir
def javadocJar = tasks.register("javadocJar", Jar) {
dependsOn(androidJavadoc)
archiveClassifier.set("javadoc")
from(androidJavadoc.map { it.destinationDir })
}

tasks.withType(Javadoc) {
Expand All @@ -152,19 +173,20 @@ tasks.withType(Javadoc) {
}

artifacts {
archives sourcesJar, javadocJar
add("archives", sourcesJar.get())
add("archives", javadocJar.get())
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
from components["release"]

artifactId = "launchdarkly-android-client-sdk"

artifact(sourcesJar)
artifact(javadocJar)
artifact(sourcesJar.get())
artifact(javadocJar.get())

pom {
name = "LaunchDarkly SDK for Android"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.launchdarkly.sdk.android">

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Expand All @@ -18,4 +17,4 @@
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.launchdarkly.sdk.android" />

</manifest>
</manifest>
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.launchdarkly.sdk.android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ public AndroidPlatformState(

connectivityReceiver = new ConnectivityReceiver();
IntentFilter filter = new IntentFilter(ConnectivityReceiver.CONNECTIVITY_CHANGE);
application.registerReceiver(connectivityReceiver, filter);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Android 13+ requires specifying exported state when registering receivers
application.registerReceiver(connectivityReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
application.registerReceiver(connectivityReceiver, filter);
}

// When we are first starting up, we can't use the ActivityLifecycleCallbacks mechanism to
// determine whether we're in the foreground or not, because the last foreground or
Expand Down
8 changes: 4 additions & 4 deletions shared-test-code/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ ext.versions = [
]

android {
compileSdkVersion(30)
buildToolsVersion = "30.0.3"
namespace "com.launchdarkly.sdk.android.sharedtest"
compileSdk = 34

defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
minSdk = 21
targetSdk = 34
}
}

Expand Down
3 changes: 1 addition & 2 deletions shared-test-code/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.launchdarkly.sdk.android.sharedtest">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Note, the classes in this module use the package com.launchdarkly.sdk.android, not
com.launchdarkly.sdk.android.sharedtest - because they need to be able to access
package-private types from the SDK. But we need to declare a different package name
Expand Down