From f4e71cf13076ef095d5d18ce6274635dd6b45c41 Mon Sep 17 00:00:00 2001 From: Grishka Date: Sat, 19 Feb 2022 03:04:04 +0300 Subject: [PATCH] Fix AppCenter SDK --- mastodon/build.gradle | 5 +++-- .../org/joinmastodon/android/AppCenterWrapper.java | 2 ++ .../java/org/joinmastodon/android/MainActivity.java | 10 ++++++++++ .../java/org/joinmastodon/android/MastodonApp.java | 5 ----- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 5a523fa98..8e4d9ba69 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -10,7 +10,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 31 - versionCode 2 + versionCode 3 versionName "0.1" } @@ -23,7 +23,8 @@ android { debuggable true } appcenterPrivateBeta{ - initWith debug + initWith release + minifyEnabled false versionNameSuffix "-priv-beta" } appcenterPublicBeta{ diff --git a/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java b/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java index f6ef2dd40..e027da17c 100644 --- a/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java +++ b/mastodon/src/appcenter/java/org/joinmastodon/android/AppCenterWrapper.java @@ -12,6 +12,8 @@ public class AppCenterWrapper{ private static final String TAG="AppCenterWrapper"; public static void init(Application app){ + if(AppCenter.isConfigured()) + return; Log.i(TAG, "initializing AppCenter SDK, build type is "+BuildConfig.BUILD_TYPE); if(BuildConfig.BUILD_TYPE.equals("appcenterPrivateBeta")) diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index e4292315f..d736f0438 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -1,11 +1,14 @@ package org.joinmastodon.android; +import android.app.Application; import android.os.Bundle; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.HomeFragment; import org.joinmastodon.android.fragments.SplashFragment; +import java.lang.reflect.InvocationTargetException; + import androidx.annotation.Nullable; import me.grishka.appkit.FragmentStackActivity; @@ -26,5 +29,12 @@ public class MainActivity extends FragmentStackActivity{ showFragmentClearingBackStack(fragment); } } + + if(BuildConfig.BUILD_TYPE.startsWith("appcenter")){ + // 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, getApplication()); + }catch(ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException ignore){} + } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java b/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java index f281a69bb..52c139022 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MastodonApp.java @@ -23,10 +23,5 @@ 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){} } }