android - 如何在flutter中将第三方android库导入java文件

标签 android flutter

我希望将 java 库导入到 flutter 应用程序。我知道我需要根据 https://flutter.io/platform-channels/ 通过 dart 桥或平台 channel 调用此 java 文件的方法。 .但是,我还不能从我试图导入可调用或可导入的库中创建方法。这些方法在android studio中单独查看java文件时可用,但在flutter查看时它们不可用。

最佳答案

使用提供的额外信息,我能够重现该问题。

要编辑原生 Android 应用,您必须在新的 Android Studio 实例中打开它:

enter image description here

添加库x io.particle:cloudsdk:0.5.0 ,您必须将其添加到 build.gradleapp子文件夹。您还必须启用 Java 1.8 支持:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

...

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'io.particle:cloudsdk:0.5.0'
}

仅当您在单独的窗口中打开 Android 项目时,IDE 才会识别该库。 Flutter 应用程序仍然可以毫无问题地编译。

要消除 Flutter 项目中的红色下划线错误,您可以卸载,然后重新加载 Android 模块(右键单击 android 文件夹 > Load/Unload modules...):

enter image description here

关于android - 如何在flutter中将第三方android库导入java文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51544535/

相关文章:

flutter - CircleAvatar 中的淡入图像

安卓/PhoneGap : destroy webview when going background instead of keepRunning=false

Android ImageView,adjustViewBounds 在 Android 4.1 中不起作用

android - 在 Android 中做消息 block

android - 使用 stripe_ payment 时 Flutter Android 应用程序在启动时崩溃

flutter - 如何在 Flutter 中启动外部应用程序(如 Skype)

android - 异常 : Unsupported Android Plugin version: 3. 6.3。 flutter 安卓工作室

flutter - 是否有通用类型的 AnimationController?如果不是,为什么?

java - 如何将 AsyncTask 从 Android 移植到 java?

java - Android 手机上的 RED 5 视频服务器...有开源端口吗?