6.4 C
Canberra
Monday, October 27, 2025

android – How can I exploit a brand new library in an older model venture?


I’m new to Flutter and at present going through a state of affairs the place I want so as to add an auto-capture characteristic for face recognition. Nonetheless, the venture makes use of an older Flutter model that can not be upgraded, so I can not combine the required library.

My code

    package deal="com.instance.test_project">
   
        
            
            
            
                
                
            
        
        

       
        
    

   ext.kotlin_version = '1.7.10'
   repositories {
       google()
       mavenCentral()
   }

   dependencies {
       classpath 'com.android.instruments.construct:gradle:4.1.0'
       classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
   }
}

allprojects {
   repositories {
       google()
       mavenCentral()
   }
}

rootProject.buildDir="../construct"
subprojects {
   venture.buildDir = "${rootProject.buildDir}/${venture.title}"
}
subprojects {
   venture.evaluationDependsOn(':app')
}

duties.register("clear", Delete) {
   delete rootProject.buildDir
}
def localPropertiesFile = rootProject.file('native.properties')
if (localPropertiesFile.exists()) {
   localPropertiesFile.withReader('UTF-8') { reader ->
       localProperties.load(reader)
   }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
   throw new GradleException("Flutter SDK not discovered. Outline location with flutter.sdk within the native.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
   flutterVersionCode="1"
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
   flutterVersionName="1.0"
}

apply plugin: 'com.android.utility'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
   compileSdkVersion 34  

   compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8
   }

   kotlinOptions {
       jvmTarget="1.8"
   }

   sourceSets {
       important.java.srcDirs += 'src/important/kotlin'
   }

   defaultConfig {
       // TODO: Specify your individual distinctive Utility ID (https://developer.android.com/studio/construct/application-id.html).
       applicationId "com.instance.test_project"
       minSdkVersion 25
       targetSdkVersion 34
       versionCode flutterVersionCode.toInteger()
       versionName flutterVersionName
   }

   buildTypes {
       launch {
           // TODO: Add your individual signing config for the discharge construct.
           // Signing with the debug keys for now, so `flutter run --release` works.
           signingConfig signingConfigs.debug
       }
       profile {
           initWith debug
       }
   }
}

flutter {
   supply '../..'
}

String storageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
repositories {
   maven {
       url '/Customers/phannhattan/Work/KAS/face_camera_module/construct/host/outputs/repo'
   }
   maven {
       url "$storageUrl/obtain.flutter.io"
   }
}

dependencies {

   implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
   debugImplementation 'com.kas.face_camera_module:flutter_debug:1.0'
   profileImplementation 'com.kas.face_camera_module:flutter_profile:1.0'
   releaseImplementation 'com.kas.face_camera_module:flutter_release:1.0'
}
package deal com.instance.test_project

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.plugin.frequent.MethodCall
import io.flutter.plugin.frequent.MethodChannel

class MainActivity : FlutterActivity() {
    non-public val CHANNEL = "com.instance.channel";
    non-public lateinit var channel: MethodChannel

    override enjoyable configureFlutterEngine(flutterEngine: FlutterEngine) {
        tremendous.configureFlutterEngine(flutterEngine)

        channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL);

        channel.setMethodCallHandler {name, end result ->
            if(name.methodology == "openFlutterModule") {
                end result.success("abc")
                startActivity(
                    FlutterActivity
                        .withNewEngine()
                        .initialRoute("/face_camera")
                        .construct(this)
                )
            }
        }
    }
}
 
import 'package deal:flutter/materials.dart';
import 'package deal:flutter/companies.dart';

void important() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : tremendous(key: key);

  // This widget is the basis of your utility.
  @override
  Widget construct(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colours.blue,
      ),
      residence: const MyHomePage(title: 'Flutter Demo Residence Web page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : tremendous(key: key);

  last String title;

  @override
  State createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  static const platform = MethodChannel('com.instance.channel');

  Future navigateToModule() async {
    strive {
      // Gửi lệnh xuống Kotlin
      String check = await platform.invokeMethod('openFlutterModule');
    } catch (e) {
      print("Did not invoke methodology: $e");
    }
  }

  @override
  Widget construct(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Textual content(widget.title),
      ),
      physique: Middle(
        youngster: Column(
          mainAxisAlignment: MainAxisAlignment.middle,
          kids: [
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '',
              style: Theme.of(context).textTheme.displayLarge,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: navigateToModule,
        tooltip: 'Increment',
        youngster: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for construct strategies.
    );
  }
}
 
  • File pubspec.yaml

    title: test_projectdescription: A brand new Flutter venture.
    
    publish_to: 'none' # Take away this line in case you want to publish to pub.dev
    
    model: 1.0.0+1
    
    atmosphere: sdk: ">=2.16.2 <3.0.0"
    
    dependencies: flutter: sdk: flutter
    
    cupertino_icons: ^1.0.2
    
    dev_dependencies: flutter_test: sdk: flutter
    
    flutter_lints: ^1.0.0
    
    flutter: uses-material-design: true
    
  • My answer: I attempted creating a brand new Flutter module with the newest model, integrating the library, and calling it from the native code within the older Flutter venture to obtain the returned picture file. Sadly, I’m unable to show the display screen or retrieve the file by means of the Flutter module.

  • May anybody present me with another answer or information me on methods to correctly implement my present method in android and ios? Thank, a lot.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles