Skip to content

Commit

Permalink
Switch Fabric to AppCenter
Browse files Browse the repository at this point in the history
Signed-off-by: tiann <[email protected]>
  • Loading branch information
tiann committed Mar 17, 2020
1 parent 1ab205c commit b0fc99d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
13 changes: 5 additions & 8 deletions VirtualApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

Properties properties = new Properties()
def localProp = file(project.rootProject.file('local.properties'))
Expand Down Expand Up @@ -90,9 +85,11 @@ dependencies {
implementation 'org.jdeferred:jdeferred-android-aar:1.2.4'
// ThirdParty
implementation 'com.jonathanfinerty.once:once:1.0.3'
aospImplementation('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
transitive = true
}

def appCenterSdkVersion = '3.0.0'
aospImplementation("com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}")
aospImplementation("com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}")

implementation 'com.kyleduo.switchbutton:library:1.4.6'
implementation 'com.allenliu.versionchecklib:library:1.8.3'
implementation 'com.github.medyo:android-about-page:1.2.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import android.content.pm.PackageInfo;
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.lody.virtual.client.VClientImpl;
import com.lody.virtual.client.core.VirtualCore;
import com.lody.virtual.os.VUserHandle;
import com.lody.virtual.remote.InstalledAppInfo;
import com.microsoft.appcenter.crashes.Crashes;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -27,18 +29,19 @@ public class MyCrashHandler extends BaseCrashHandler {
public void handleUncaughtException(Thread t, Throwable e) {
SharedPreferences sp = VirtualCore.get().getContext().getSharedPreferences(CRASH_SP, Context.MODE_MULTI_PROCESS);

Map<String, String> properties = new HashMap<>();
try {
ApplicationInfo currentApplicationInfo = VClientImpl.get().getCurrentApplicationInfo();
if (currentApplicationInfo != null) {
String packageName = currentApplicationInfo.packageName;
String processName = currentApplicationInfo.processName;

Crashlytics.setString("process", processName);
Crashlytics.setString("package", packageName);
properties.put("process", processName);
properties.put("package", packageName);

int userId = VUserHandle.myUserId();

Crashlytics.setInt("uid", userId);
properties.put("uid", String.valueOf(userId));

InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(packageName, 0);
if (installedAppInfo != null) {
Expand All @@ -47,8 +50,8 @@ public void handleUncaughtException(Thread t, Throwable e) {
String versionName = packageInfo.versionName;
int versionCode = packageInfo.versionCode;

Crashlytics.setString("versionName", versionName);
Crashlytics.setInt("versionCode", versionCode);
properties.put("versionName", versionName);
properties.put("versionCode", String.valueOf(versionCode));

}
}
Expand All @@ -64,7 +67,7 @@ public void handleUncaughtException(Thread t, Throwable e) {
if (exceptionType.equals(lastCrashType) && (now - lastCrash) < TimeUnit.MINUTES.toMillis(1)) {
// continues crash, do not upload
} else {
Crashlytics.logException(e);
Crashes.trackError(e, properties, null);
}

Log.i(TAG, "uncaught :" + t, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import android.app.Application;

import com.crashlytics.android.Crashlytics;
import com.lody.virtual.client.core.VirtualCore;

import io.fabric.sdk.android.Fabric;
import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.crashes.Crashes;

/**
* @author weishu
Expand All @@ -18,15 +18,17 @@ public MyVirtualInitializer(Application application, VirtualCore core) {

@Override
public void onMainProcess() {
Fabric.with(this.application, new Crashlytics());
AppCenter.start(application, "bf5e74bd-3795-49bd-95c8-327db494dd11",
Analytics.class, Crashes.class);
super.onMainProcess();
}

@Override
public void onVirtualProcess() {

// For Crash statics
Fabric.with(application, new Crashlytics());
AppCenter.start(application, "bf5e74bd-3795-49bd-95c8-327db494dd11",
Analytics.class, Crashes.class);

super.onVirtualProcess();

Expand Down
4 changes: 0 additions & 4 deletions VirtualApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
android:value="com.android.support:design:25.4.0"
tools:replace="android:value" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="797c6ad1f87c908a4d7f6e8091e6466848b1611d" />

<activity
android:name=".splash.SplashActivity"
android:screenOrientation="portrait"
Expand Down
6 changes: 0 additions & 6 deletions VirtualApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ buildscript {
url 'https://maven.google.com/'
name 'Google'
}
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle-experimental:0.11.1'
// We recommend changing it to the latest version from our changelog:
// https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
classpath 'io.fabric.tools:gradle:1.27.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down

0 comments on commit b0fc99d

Please sign in to comment.