Developer

App Center SDK for Flutter

This package supports all the Analytics, Crashes and Distribute parts of the sdk.


!WARNING Soon will be deprecated because of Visual Studio App Center is scheduled for retirement on March 31, 2025._

Installation

dart pub add:dev appcenter_sdk -u https://gitea.whitelabel.mobile.embedit.dev/api/packages/platform/pub/

!IMPORTANT You need access token for fetching from private pub repository. ELI add token automatically

Usage

import 'package:appcenter/appcenter.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AppCenter.start(secret: '<APP-SECRET>');
  FlutterError.onError = (final details) async {
    await AppCenterCrashes.trackException(
      message: details.exception.toString(),
      type: details.exception.runtimeType,
      stackTrace: details.stack,
    );
  };
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(final BuildContext context) => MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('App Center Sdk'),
          ),
          body: Center(
            child: ElevatedButton(
              onPressed: () {
                int.parse('not a number');
              },
              child: const Text('TrackException'),
            ),
          ),
        ),
      );
}

AppCenter

await AppCenter.start('secret');
await AppCenter.enable();
await AppCenter.disable();
final isEnabled = await AppCenter.isEnabled();
final isConfigured = await AppCenter.isConfigured();
final installId = await AppCenter.getInstallId();
final isRunningInAppCenterTestCloud = await AppCenter.isRunningInAppCenterTestCloud();

AppCenter Analytics

  await AppCenterAnalytics.trackEvent(name: 'A Event', properties: {'property':'value'}, flags: 1);
  await AppCenterAnalytics.pause();
  await AppCenterAnalytics.resume();
  await AppCenterAnalytics.enable();
  await AppCenterAnalytics.disable();
  final isEnabled = await AppCenterAnalytics.isEnabled();
  await AppCenterAnalytics.enableManualSessionTracker();
  await AppCenterAnalytics.startSession();
  final isSetted =  AppCenterAnalytics.setTransmissionInterval(3);

AppCenter Crashes

  await generateTestCrash();
  final hasReceivedMemoryWarningInLastSession = AppCenterCrashes.hasReceivedMemoryWarningInLastSession();
  final hasCrashedInLastSession = AppCenterCrashes.hasCrashedInLastSession();
  await AppCenterCrashes.enable();
  await AppCenterCrashes.disable();
  final isEnabled = AppCenterCrashes.isEnabled();
  await AppCenterCrashes.trackException(message: 'MessageException', type: MessageException.runtimeType, stackTrace: StackTrace.fromString('stackTraceString'), properties: {'property':'value'});

When using the trackException, the flutter stack trace will appear in App Center.

Exceptions are readable only without obfuscation in flutter apps

AppCenter Distribute

Distribution of testing build to the AppCenter

In the Android build, it is necessary to define the correct dependencies for flavor and build type.

Edit the file /android/app/build.gradle

// Add placeholders for configurations and remove dependencies that should not be available in the release version.
configurations {
    productionReleaseImplementation{
        exclude group: 'com.microsoft.appcenter', module: 'appcenter-distribute'
    }
    preprodReleaseImplementation{
        exclude group: 'com.microsoft.appcenter', module: 'appcenter-distribute'
    }
}

dependencies {
    def appCenterSdkVersion = '5.0.2'
    ...

    // add standard dependency
    implementation("com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}")
    
    // we have to add an dependency for implementation of distribute for Google Play
    productionReleaseImplementation("com.microsoft.appcenter:appcenter-distribute-play:${appCenterSdkVersion}")
    preprodReleaseImplementation("com.microsoft.appcenter:appcenter-distribute-play:${appCenterSdkVersion}")

}

Build for distribution to AppCenter

To work with version updates, it is necessary to define the necessary permissions.

<!-- andoroid/app/src/production/AnddroidManifest.xml --> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</manifest>

Build for distribution to Google Play

The build of the application, which is for production, should not contain permissions that are necessary for AppCenter, unless required by other needs (rules are necessary for the operation of the application)

<!-- andoroid/app/src/productionRelease/AnddroidManifest.xml --> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" tools:node="remove" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" tools:node="remove" />
</manifest>

Pigeon

Since I always forget the command, I noted it here.

dart run pigeon \
  --input pigeons/messages.dart \
  --dart_out lib/src/messages.g.dart \
  --swift_out ios/Classes/Messages.g.swift \
  --kotlin_out android/src/main/kotlin/zoo/cityboy/appcenter/Messages.g.kt \
  --kotlin_package "zoo.cityboy.appcenter"

Copyright © 2025. All rights reserved.