Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

enhancement: use AGP 4 features #366

Merged
merged 11 commits into from
May 29, 2020
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
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
ANDROID_NDK_HOME: "C:\\android-sdk-windows\\ndk-bundle"
ANDROID_BUILD_VERSION: 29
ANDROID_TOOLS_VERSION: 29.0.3
ANDROID_NDK_VERSION: 21.1.6352462
ANDROID_NDK_VERSION: 21.0.6113669
ANDROID_CMAKE_VERSION: 3.10.2.4988404
GRADLE_OPTS: -Dorg.gradle.daemon=false
SDK_TOOLS_URL: https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip
Expand All @@ -22,7 +22,7 @@ cache:
- "%USERPROFILE%\\.gradle\\caches"
- "%USERPROFILE%\\.m2\\repository"
build_script:
- cmd: gradlew.bat clean cleanBuildCache build bintrayUpload -PbintrayUser=dryUser -PbintrayKey=dryKey
- cmd: gradlew.bat build bintrayUpload -PbintrayUser=dryUser -PbintrayKey=dryKey
artifacts:
- path: '**\libs\*sentry*.jar'
- path: '**\outputs\aar\*sentry*release*.aar'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
CMAKE_VERSION: "3.10.2.4988404"
# NDK_VERSION: "20.0.5594570"
NDK_VERSION: "21.0.6113669"

jobs:
build:
Expand All @@ -32,12 +32,12 @@ jobs:
with:
java-version: 1.8

# sudo is necessary for linux
# sudo is required for linux

# 20.0.5594570 is not used, but it needs to be installed
# https://github.com/actions/virtual-environments/issues/60
# - name: Install NDK 20.0
# run: sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;${NDK_VERSION}"
# required because ubuntu doesn't have NDK 21.0 installed by default
- name: Install NDK 21.0
run: sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;${NDK_VERSION}"

# required because macOS doesn't have cmake 3.10 installed by default
- name: Install cmake 3.10.2
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_install:
- touch $HOME/.android/repositories.cfg
- yes | sdkmanager --update
install:
- echo y | sdkmanager "ndk;21.1.6352462" >/dev/null
- echo y | sdkmanager "ndk;21.0.6113669" >/dev/null
- echo y | sdkmanager "cmake;3.10.2.4988404" >/dev/null
before_script:
- export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object Config {
val kotlinStdLib = "stdlib-jdk8"

object BuildPlugins {
val androidGradle = "com.android.tools.build:gradle:3.6.3"
val androidGradle = "com.android.tools.build:gradle:4.0.0"
val kotlinGradlePlugin = "gradle-plugin"
}

Expand All @@ -16,7 +16,7 @@ object Config {
val targetSdkVersion = sdkVersion
val compileSdkVersion = sdkVersion
val cmakeVersion = "3.10.2"
val ndkVersion = "21.1.6352462"
val ndkVersion = "21.0.6113669" // 21.1.6352462 when https://discuss.lgtm.com/t/android-ndk-v21-1-6352462-is-not-available/2910 is fixed
val abiFilters = listOf("x86", "armeabi-v7a", "x86_64", "arm64-v8a")
}

Expand Down
13 changes: 13 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ android.useAndroidX=true
# Release information
buildVersionCode=20029
versionName=2.1.4-SNAPSHOT

# disable renderscript, it's enabled by default
android.defaults.buildfeatures.renderscript=false

# disable shader compilation, it's enabled by default
android.defaults.buildfeatures.shaders=false

# disable aidl files, it's enabled by default
android.defaults.buildfeatures.aidl=false

# TODO: Enable Prefab https://android-developers.googleblog.com/2020/02/native-dependencies-in-android-studio-40.html
# android.enablePrefab=true
# android.prefabVersion=1.0.0
11 changes: 5 additions & 6 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ android {
targetSdkVersion(Config.Android.targetSdkVersion)
minSdkVersion(Config.Android.minSdkVersion)

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

versionName = project.version.toString()
Expand All @@ -39,6 +33,11 @@ android {
}
}

buildFeatures {
// Determines whether to support injecting custom variables into the module's R class.
resValues = false
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
20 changes: 7 additions & 13 deletions sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ android {
targetSdkVersion(Config.Android.targetSdkVersion)
minSdkVersion(Config.Android.minSdkVersionNdk) // NDK requires a higher API level than core.

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

versionName = project.version.toString()
Expand All @@ -46,18 +40,18 @@ android {
setAbiFilters(Config.Android.abiFilters)
ndkVersion = Config.Android.ndkVersion
}
}

// replace with https://issuetracker.google.com/issues/72050365 once released.
libraryVariants.all {
generateBuildConfigProvider?.configure {
enabled = false
}
}
buildFeatures {
// Determines whether to generate a BuildConfig class.
buildConfig = false
// Determines whether to support injecting custom variables into the module's R class.
resValues = false
}

externalNativeBuild {
cmake {
setVersion(Config.Android.cmakeVersion)
version = Config.Android.cmakeVersion
setPath("CMakeLists.txt")
}
}
Expand Down
10 changes: 5 additions & 5 deletions sentry-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

// replace with https://issuetracker.google.com/issues/72050365 once released.
libraryVariants.all {
generateBuildConfigProvider?.configure {
enabled = false
}
buildFeatures {
// Determines whether to generate a BuildConfig class.
buildConfig = false
// Determines whether to support injecting custom variables into the module's R class.
resValues = false
}
}

Expand Down
27 changes: 25 additions & 2 deletions sentry-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ android {
}
}

buildFeatures {
// Determines whether to support View Binding.
// Note that the viewBinding.enabled property is now deprecated.
viewBinding = true
// Determines whether to support injecting custom variables into the module's R class.
resValues = false
}

dependenciesInfo {
// Disables dependency metadata when building APKs.
includeInApk = false
// Disables dependency metadata when building Android App Bundles.
includeInBundle = false
}

externalNativeBuild {
cmake {
setVersion(Config.Android.cmakeVersion)
version = Config.Android.cmakeVersion
setPath("CMakeLists.txt")
}
}
Expand All @@ -51,12 +66,20 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
manifestPlaceholders = mapOf(
"sentryDebug" to true
)
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("debug") // to be able to run release mode
isShrinkResources = true

manifestPlaceholders = mapOf(
"sentryDebug" to false
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<meta-data android:name="io.sentry.dsn" android:value="https://f7f320d5c3a54709be7b28e0f2ca7081@sentry.io/1808954" />

<!-- how to enable Sentry's debug mode-->
<meta-data android:name="io.sentry.debug" android:value="true" />
<meta-data android:name="io.sentry.debug" android:value="${sentryDebug}" />

<!-- how to set a custom debug level-->
<!-- <meta-data android:name="io.sentry.debug.level" android:value="info" />-->
Expand Down
85 changes: 41 additions & 44 deletions sentry-sample/src/main/java/io/sentry/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import io.sentry.core.Sentry;
import io.sentry.core.SentryLevel;
import io.sentry.core.protocol.User;
import io.sentry.sample.databinding.ActivityMainBinding;
import java.util.Collections;
import timber.log.Timber;

Expand All @@ -13,57 +13,54 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());

Timber.i("Sentry.isEnabled() = %s", Sentry.isEnabled());

findViewById(R.id.crash_from_java)
.setOnClickListener(
view -> {
throw new RuntimeException("Uncaught Exception from Java.");
});
binding.crashFromJava.setOnClickListener(
view -> {
throw new RuntimeException("Uncaught Exception from Java.");
});

binding.sendMessage.setOnClickListener(view -> Sentry.captureMessage("Some message."));

findViewById(R.id.send_message)
.setOnClickListener(view -> Sentry.captureMessage("Some message."));
binding.captureException.setOnClickListener(
view ->
Sentry.captureException(
new Exception(new Exception(new Exception("Some exception.")))));

findViewById(R.id.capture_exception)
.setOnClickListener(
view ->
Sentry.captureException(
new Exception(new Exception(new Exception("Some exception.")))));
binding.breadcrumb.setOnClickListener(
view -> {
Sentry.addBreadcrumb("Breadcrumb");
Sentry.setExtra("extra", "extra");
Sentry.setFingerprint(Collections.singletonList("fingerprint"));
Sentry.setTransaction("transaction");
User user = new User();
user.setUsername("username");
Sentry.setUser(user);
Sentry.setTag("tag", "tag");
Sentry.captureException(new Exception("Some exception with scope."));
});

findViewById(R.id.breadcrumb)
.setOnClickListener(
view -> {
Sentry.addBreadcrumb("Breadcrumb");
Sentry.setExtra("extra", "extra");
Sentry.setFingerprint(Collections.singletonList("fingerprint"));
Sentry.setLevel(SentryLevel.INFO);
Sentry.setTransaction("transaction");
User user = new User();
user.setUsername("username");
Sentry.setUser(user);
Sentry.setTag("tag", "tag");
Sentry.captureException(new Exception("Some exception with scope."));
});
binding.nativeCrash.setOnClickListener(view -> NativeSample.crash());

findViewById(R.id.native_crash).setOnClickListener(view -> NativeSample.crash());
binding.nativeCapture.setOnClickListener(view -> NativeSample.message());

findViewById(R.id.native_capture).setOnClickListener(view -> NativeSample.message());
binding.anr.setOnClickListener(
view -> {
// Try cause ANR by blocking for 2.5 seconds.
// By default the SDK sends an event if blocked by at least 4 seconds.
// The time was configurable (see manifest) to 1 second for demo purposes.
// NOTE: By default it doesn't raise if the debugger is attached. That can also be
// configured.
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});

findViewById(R.id.anr)
.setOnClickListener(
view -> {
// Try cause ANR by blocking for 2.5 seconds.
// By default the SDK sends an event if blocked by at least 5 seconds.
// The time was configurable (see manifest) to 1 second for demo purposes.
// NOTE: By default it doesn't raise if the debugger is attached. That can also be
// configured.
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
setContentView(binding.getRoot());
}
}