diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb308bd..1b35d18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -164,12 +164,14 @@ jobs: fail-fast: false matrix: host: [ubuntu] + version: ['3.22.x', 'any'] steps: - uses: actions/checkout@v4 with: submodules: 'recursive' - uses: subosito/flutter-action@v2 with: + flutter-version: ${{ matrix.version }} channel: 'stable' cache: true - uses: actions/setup-java@v4 @@ -183,7 +185,7 @@ jobs: - name: Upload uses: actions/upload-artifact@v4 with: - name: fvp-example-android-${{ matrix.host }} + name: fvp-example-android-${{ matrix.host }}-${{ matrix.version }} path: example/fvp_example_android.apk diff --git a/android/build.gradle b/android/build.gradle index c1170f8..171ee7f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -55,7 +55,7 @@ android { } defaultConfig { - minSdkVersion 21 // lower version error in ndk 26 + minSdkVersion 21 // lower version error in ndk 26. requires flutter > 3.19 externalNativeBuild { cmake { @@ -86,3 +86,39 @@ android { } } } + +def flutterSdkVersion = { + def properties = new Properties() + file(rootDir.absolutePath + "/local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + if (flutterSdkPath == null) { + flutterSdkPath = System.env.FLUTTER_ROOT // from flutter.groovy + } + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + def version = file(flutterSdkPath + "/version") + assert version.exists(), "flutter version file not found" + return version.text.trim() +}() + +println "flutterSdkVersion: ${flutterSdkVersion}" + +def preprocessJava(Map textMap) { + def f = file('src/main/java/com/mediadevkit/fvp/FvpPlugin.java') + assert f.exists(), path + "not found" + def content = f.text + def newContent = content + textMap.forEach { oldText, newText -> + newContent = newContent.replaceAll(oldText, newText) + } + if (content != newContent) { + println "rewrite " + f.path + f.write(newContent) + } +} +// VersionNumber is deprecated +if (Float.parseFloat(flutterSdkVersion.replaceAll('\\.[0-9]*$', '')) < 3.24) { + println 'Impeller is not perfect for flutter < 3.24' + preprocessJava(['//// FLUTTER_3.24_BEGIN': '/\\*// FLUTTER_3.24_BEGIN-', '//// FLUTTER_3.24_END': '\\*/// FLUTTER_3.24_END-']) +} else { + preprocessJava(['/\\*// FLUTTER_3.24_BEGIN-': '//// FLUTTER_3.24_BEGIN', '\\*/// FLUTTER_3.24_END-': '//// FLUTTER_3.24_END']) +} diff --git a/android/src/main/java/com/mediadevkit/fvp/FvpPlugin.java b/android/src/main/java/com/mediadevkit/fvp/FvpPlugin.java index 7abc06f..d0aa0f7 100644 --- a/android/src/main/java/com/mediadevkit/fvp/FvpPlugin.java +++ b/android/src/main/java/com/mediadevkit/fvp/FvpPlugin.java @@ -87,6 +87,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { textures.put(texId, te); surfaces.put(texId, surface); result.success(texId); +//// FLUTTER_3.24_BEGIN if (sp != null) { // FIXME: requires 3.24. how to build conditionally? // 3.24: https://docs.flutter.dev/release/breaking-changes/android-surface-plugins sp.setCallback( @@ -109,6 +110,7 @@ public void onSurfaceDestroyed() { } ); } +//// FLUTTER_3.24_END } else if (call.method.equals("ReleaseRT")) { final int texId = call.argument("texture"); // 32bit int, 0, 1, 2 .... but SurfaceTexture.id() is long final long texId64 = texId; // MUST cast texId to long, otherwise remove() error diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 2197491..2193863 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -38,7 +38,7 @@ android:value="2" /> + android:value="true" />