diff --git a/build.gradle b/build.gradle index f5b23f03..a2d6a92f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { classpath "com.android.tools.build:gradle:7.0.4" - + classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 3001ae79..ef522185 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.application' + id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' } android { @@ -10,7 +11,7 @@ android { minSdk 23 targetSdk 31 versionCode 1 - versionName "1.0" + versionName "0.1" } buildTypes { @@ -18,12 +19,31 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug{ + debuggable true + } + appcenterPrivateBeta{ + initWith debug + versionNameSuffix "-priv-beta" + } + appcenterPublicBeta{ + initWith release + versionNameSuffix "-beta" + } } compileOptions { sourceCompatibility JavaVersion.VERSION_15 targetCompatibility JavaVersion.VERSION_15 coreLibraryDesugaringEnabled true } + sourceSets{ + appcenterPrivateBeta{ + setRoot "src/appcenter" + } + appcenterPublicBeta{ + setRoot "src/appcenter" + } + } } dependencies { @@ -43,4 +63,10 @@ dependencies { implementation 'org.parceler:parceler-api:1.1.12' annotationProcessor 'org.parceler:parceler:1.1.12' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' + + def appCenterSdkVersion = "4.4.2" + appcenterPrivateBetaImplementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" + appcenterPrivateBetaImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}" + appcenterPublicBetaImplementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" + appcenterPublicBetaImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}" } \ No newline at end of file diff --git a/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java b/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java new file mode 100644 index 00000000..f6ef2dd4 --- /dev/null +++ b/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java @@ -0,0 +1,21 @@ +package org.joinmastodon.android; + +import android.app.Application; +import android.util.Log; + +import com.microsoft.appcenter.AppCenter; +import com.microsoft.appcenter.crashes.Crashes; +import com.microsoft.appcenter.distribute.Distribute; +import com.microsoft.appcenter.distribute.UpdateTrack; + +public class AppCenterWrapper{ + private static final String TAG="AppCenterWrapper"; + + public static void init(Application app){ + Log.i(TAG, "initializing AppCenter SDK, build type is "+BuildConfig.BUILD_TYPE); + + if(BuildConfig.BUILD_TYPE.equals("appcenterPrivateBeta")) + Distribute.setUpdateTrack(UpdateTrack.PRIVATE); + AppCenter.start(app, BuildConfig.appCenterKey, Distribute.class, Crashes.class); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java b/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java index c4ccfaf4..f281a69b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java @@ -4,6 +4,8 @@ import android.annotation.SuppressLint; import android.app.Application; import android.content.Context; +import java.lang.reflect.InvocationTargetException; + import me.grishka.appkit.imageloader.ImageCache; import me.grishka.appkit.utils.NetworkUtils; @@ -21,5 +23,10 @@ public class MastodonApp extends Application{ ImageCache.setParams(params); NetworkUtils.setUserAgent("MastodonAndroid/"+BuildConfig.VERSION_NAME); context=getApplicationContext(); + + // Call the appcenter SDK wrapper through reflection because it is only present in beta builds + try{ + Class.forName("org.joinmastodon.android.AppCenterWrapper").getMethod("init", Application.class).invoke(null, this); + }catch(ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException ignore){} } }