Add AppCenter SDK

This commit is contained in:
Grishka 2022-02-15 23:09:39 +03:00
parent 6a35d78f99
commit 006fde1686
4 changed files with 56 additions and 2 deletions

View File

@ -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
}

View File

@ -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}"
}

View File

@ -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);
}
}

View File

@ -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){}
}
}