Flutter SDK

集成 SDK

直接从 GitHub 获取 SDK 的源码并集成到项目中。

添加依赖

以工程flutter_app为例,在pubspec.yaml文件中添加依赖

dependencies:
growingio_sdk_tracker_plugin:
git:
ref: master
url: https://github.com/growingio/flutter-growingio-sdk-tracker-plugin.git

然后执行 flutter pub get 指令

iOS 工程配置

sdk需要初始化操作,否则会异常退出

AppDelegate文件中添加初始化sdk代码,例如如下所示:

#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
#import <GrowingAnalytics/GrowingTracker.h>
#import <GrowingAnalytics/GrowingTrackConfiguration.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
GrowingTrackConfiguration *configuration = [GrowingTrackConfiguration configurationWithProjectId:@"0a1b4118dd954ec3bcc69da5138bdb96"];
configuration.debugEnabled = YES;
[GrowingTracker startWithConfiguration:configuration launchOptions:launchOptions];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end

使用Xcode,选择Targets->Info->URL Types配置好相关的url scheme

Android工程配置

  • 新建一个MyApplication继承自FlutterApplication

package com.example.flutter_app;
import com.growingio.android.sdk.track.TrackConfiguration;
import com.growingio.android.sdk.track.GrowingTracker;
import io.flutter.app.FlutterApplication;
public class MyApplication extends FlutterApplication {
private static TrackConfiguration sConfiguration;
@Override
public void onCreate() {
super.onCreate();
if (sConfiguration == null) {
sConfiguration = new TrackConfiguration("bfc5d6a3693a110d", "growing.d80871b41ef40518")
.setUploadExceptionEnabled(false)
.setDebugEnabled(true)
.setOaidEnabled(false);
}
GrowingTracker.startWithConfiguration(this, sConfiguration);
}
}
  • 并修改 AndroidManifest.xml文件中android:name字段

<application
android:name="com.example.growingio_sdk_tracker_plugin_example.MyApplication" //修改这里
...
  • app下的build.gradle添加配置参数

android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_app"
minSdkVersion 17 //提示:这里可能版本小于17,修改为17可以避免报错
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
resValue("string", "growingio_project_id", "9926fc6c1189e2fb") //这里是你的工程id
resValue("string", "growingio_url_scheme", "growing.da7e6c2879469314") //这里是你的url scheme
  • app下的build.gradle中添加 GrowingIO Tracker SDK

dependencies {
implementation 'com.growingio.android:tracker:latest.release' //可以指定你需要的版本 >3.0.0
}

之后,运行你的app,即可进行正常埋点。