提交 c00cb0fe authored 作者: jiangjun's avatar jiangjun

增加 bugly 初始化方法

上级 ae0ded9e
......@@ -31,5 +31,13 @@ android {
defaultConfig {
minSdkVersion 16
ndk {
// 设置支持的SO库架构
abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
}
}
dependencies {
implementation 'com.tencent.bugly:crashreport:4.1.9.2'
}
\ No newline at end of file
......@@ -2,37 +2,58 @@ package com.example.hi_bugly;
import androidx.annotation.NonNull;
import com.tencent.bugly.crashreport.CrashReport;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
/** HiBuglyPlugin */
/**
* HiBuglyPlugin
*/
public class HiBuglyPlugin implements FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
private FlutterPluginBinding flutterPluginBinding;
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "hi_bugly");
channel.setMethodCallHandler(this);
}
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
this.flutterPluginBinding = flutterPluginBinding;
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "hi_bugly");
channel.setMethodCallHandler(this);
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else {
result.notImplemented();
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "getPlatformVersion":
result.success("Android " + android.os.Build.VERSION.RELEASE);
break;
case "initialize":
String appID = "";
boolean debug = false;
if (call.hasArgument("appID")) {
appID = call.argument("appID");
}
if (call.hasArgument("debug")) {
debug = Boolean.TRUE.equals(call.argument("debug"));
}
CrashReport.initCrashReport(flutterPluginBinding.getApplicationContext(), appID, debug);
result.success(true);
break;
default:
result.notImplemented();
break;
}
}
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hi_bugly_example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:label="hi_bugly_example"
android:name="${applicationName}"
......
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
......@@ -31,8 +31,8 @@ class _MyAppState extends State<MyApp> {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await _hiBuglyPlugin.getPlatformVersion() ?? 'Unknown platform version';
platformVersion = await _hiBuglyPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
......@@ -54,8 +54,16 @@ class _MyAppState extends State<MyApp> {
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
body: Column(
children: [
Text('Running on: $_platformVersion\n'),
MaterialButton(
onPressed: () {
_hiBuglyPlugin.initialize(appID: '123456', debug: true);
},
child: const Text('初始化'),
),
],
),
),
);
......
import 'hi_bugly_platform_interface.dart';
class HiBugly {
Future<String?> getPlatformVersion() {
return HiBuglyPlatform.instance.getPlatformVersion();
}
Future<bool?> initialize({
required String appID,
bool debug = false,
}) {
return HiBuglyPlatform.instance.initialize(
appID: appID,
debug: debug,
);
}
}
......@@ -11,12 +11,22 @@ class MethodChannelHiBugly extends HiBuglyPlatform {
@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
final version =
await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
@override
Future<bool?> initialize() async {
return await methodChannel.invokeMethod('initialize');
Future<bool?> initialize({
required String appID,
bool debug = false,
}) async {
return await methodChannel.invokeMethod(
'initialize',
{
'appID': appID,
'debug': debug,
},
);
}
}
......@@ -27,7 +27,10 @@ abstract class HiBuglyPlatform extends PlatformInterface {
throw UnimplementedError('platformVersion() has not been implemented.');
}
Future<bool?> initialize() {
Future<bool?> initialize({
required String appID,
bool debug = false,
}) {
throw UnimplementedError('initialize() has not been implemented.');
}
}
......@@ -7,12 +7,14 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockHiBuglyPlatform
with MockPlatformInterfaceMixin
implements HiBuglyPlatform {
@override
Future<String?> getPlatformVersion() => Future.value('42');
@override
Future<bool?> initialize() {
Future<bool?> initialize({
required appID,
bool debug = false,
}) {
// TODO: implement initialize
throw UnimplementedError();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论