Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flutter compatibility 3.29 #558

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.graphics.Matrix;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -27,7 +28,6 @@
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.renderer.FlutterRenderer;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry.Registrar;

public class InstabugFlutterPlugin implements FlutterPlugin, ActivityAware {
private static final String TAG = InstabugFlutterPlugin.class.getName();
Expand All @@ -37,16 +37,35 @@ public class InstabugFlutterPlugin implements FlutterPlugin, ActivityAware {

/**
* Embedding v1
* This method is required for compatibility with apps that don't use the v2 embedding.
*/
@SuppressWarnings("deprecation")
public static void registerWith(Registrar registrar) {
activity = registrar.activity();
register(registrar.context().getApplicationContext(), registrar.messenger(), (FlutterRenderer) registrar.textures());
}

@SuppressWarnings("deprecation")
public static void registerWith(Object registrar) {
try {
// Use reflection to access the Registrar class and its methods
Class<?> registrarClass = Class.forName("io.flutter.plugin.common.PluginRegistry.Registrar");
Activity activity = (Activity) registrarClass.getMethod("activity").invoke(registrar);
Context context = (Context) registrarClass.getMethod("context").invoke(registrar);
BinaryMessenger messenger = (BinaryMessenger) registrarClass.getMethod("messenger").invoke(registrar);
FlutterRenderer renderer = (FlutterRenderer) registrarClass.getMethod("textures").invoke(registrar);

// Set the activity and register with the context
InstabugFlutterPlugin.activity = activity;
registerWithContext(context.getApplicationContext(), messenger, renderer);
System.out.println("old app");
} catch (Exception e) {
Log.e(TAG, "Failed to register with v1 embedding. Cause: " + e);
}
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
register(binding.getApplicationContext(), binding.getBinaryMessenger(), (FlutterRenderer) binding.getTextureRegistry());
registerWithContext(
binding.getApplicationContext(),
binding.getBinaryMessenger(),
(FlutterRenderer) binding.getTextureRegistry()
);
}

@Override
Expand Down Expand Up @@ -74,14 +93,18 @@ public void onDetachedFromActivity() {
activity = null;
}

private static void register(Context context, BinaryMessenger messenger, FlutterRenderer renderer) {
/**
* Shared logic for both v1 and v2 embeddings.
*/
private static void registerWithContext(Context context, BinaryMessenger messenger, FlutterRenderer renderer) {
final Callable<Bitmap> screenshotProvider = new Callable<Bitmap>() {
@Override
public Bitmap call() {
return takeScreenshot(renderer);
}
};

// Initialize all APIs
ApmApi.init(messenger);
BugReportingApi.init(messenger);
CrashReportingApi.init(messenger);
Expand All @@ -102,10 +125,17 @@ private static Bitmap takeScreenshot(FlutterRenderer renderer) {
final Bitmap bitmap = renderer.getBitmap();
view.setDrawingCacheEnabled(false);

return bitmap;
return flipBitmap(bitmap);
} catch (Exception e) {
Log.e(TAG, "Failed to take screenshot using " + renderer.toString() + ". Cause: " + e);
return null;
}
}
}
private static Bitmap flipBitmap(Bitmap bitmap) {
// Use Matrix to flip the bitmap vertically (scale Y-axis by -1)
Matrix matrix = new Matrix();
matrix.preScale(1, -1); // Flip vertically
Bitmap flippedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return flippedBitmap;
}
}
15 changes: 12 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 56S6Q9SA8U;
DEVELOPMENT_TEAM = 33PPV4R6VL;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -569,6 +571,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.instabug.InstabugSample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -688,8 +691,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 56S6Q9SA8U;
DEVELOPMENT_TEAM = 33PPV4R6VL;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -706,6 +711,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.instabug.InstabugSample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -719,8 +725,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 56S6Q9SA8U;
DEVELOPMENT_TEAM = 33PPV4R6VL;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -737,6 +745,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.instabug.InstabugSample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {
WidgetsFlutterBinding.ensureInitialized();

Instabug.init(
token: 'ed6f659591566da19b67857e1b9d40ab',
token: '89ba56d7b0d4b53ccc79c9e89f337b63',
invocationEvents: [InvocationEvent.floatingButton],
debugLogsLevel: LogLevel.verbose,
);
Expand Down
Empty file modified scripts/pigeon.sh
100644 → 100755
Empty file.