连接flutter应用程序与firebase之后,我可以在物理设备上启动应用程序

发布于 2025-02-10 18:24:11 字数 3441 浏览 2 评论 0 原文

我是Flutter和Firebase的新手。我的问题是,我能够在物理设备上运行flutter应用程序以测试UI,但是将其连接到firebase并尝试像以前使用的那样启动该应用程序后,它只会运行 gradle任务“组装调试” 少于一分钟,终止而无需发送任何形式的反馈或错误。

我跟随 this 这就是我的 build.gradle.gradle file.gradle file.gradle file.gradle file 看起来像:

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.12'
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的 build.gradle文件

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.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 found. Define location with flutter.sdk in the local.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.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.sabra.cadre_permanence_marjane"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

我也尝试在 package_name > google-services.json 要匹配的文件(请告诉我是否不应该这样做),并检查是否flutter识别我的设备以防万一:

命令提示:flutter设备

I am new to Flutter and Firebase. My problem is that I was able to run my Flutter app on my physical device to test the ui perfectly fine but after I connected it to Firebase and tried to launch the app like I used it to do before, it will just run the gradle task 'assemble debug' for less than a minute and terminate without sending any kind of feedback or error.

I followed this and that's how my build.gradle file look like:

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.12'
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and that's my build.gradle file in the app directory :

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.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 found. Define location with flutter.sdk in the local.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.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.sabra.cadre_permanence_marjane"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Also I tried changing the package_name in each member of the client array in the google-services.json file to match (tell me if I shouldn't have done that) and checked if Flutter recognize my device just in case:

command prompt: flutter devices

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-02-17 18:24:11

遵循的步骤:(建议在Android Studio中尝试)

  1. 连接到Firebase后,在Android-> App; App; app; app; json文件中添加Google-services.json文件。
  2. 检查是否有名为“ [Project_Name] _android.iml'的文件,或者不在Android文件夹下方。
  3. 如果不是,请在名为“ [project_name] _android.iml'的Android文件夹下制作文件。
  4. 复制该文件下的以下代码。
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
  </component>
</module>
  1. 关闭在IDE中打开的所有文件。
  2. 转到任何build.gradle文件(项目级别或应用程序级别)。
  3. 打开该文件时,您会在文件顶部看到横幅。在横幅的右侧注意。您将看到一个选项“在Android Studio中进行编辑”。单击该选项。
  4. Android Studio的许可将打开一个新窗口。允许打开为“新窗口”。
  5. 等到“ Gradle Build”操作完成。您可以在新打开的窗口的底部看到进度。
  6. 完成后,关闭新窗口。
  7. 剧烈的清洁
  8. 扑面酒吧可以
  9. 运行该项目。

玩得开心。谢谢。

Steps to follow: (Recommended to try in Android Studio)

  1. After connecting to firebase, add the google-services.json file under android->app folder.
  2. Check if there is any file named '[project_name]_android.iml' or not under android folder.
  3. if not, make a file under the android folder named '[project_name]_android.iml'.
  4. Copy-paste the following code under that file.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR
quot; />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
  </component>
</module>
  1. Close all files that open in IDE.
  2. Go to any build.gradle file(project level or app level).
  3. When you open that file, you will see a banner at the top of the file. Notice at the right side of the banner. You will see an option 'Open for Editing in Android Studio'. Click that option.
  4. A Permission will asked by Android Studio to open a new window. Give Permission to open as 'New Window'.
  5. Wait until "Gradle Build" operation is completed. You can see progress at the bottom of the newly opened window.
  6. After complete Progress close the new window.
  7. flutter clean
  8. flutter pub get
  9. run the project.

Have fun. Thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文