简体   繁体   English

尝试将 Firebase 依赖项添加到 Qt 项目时生成错误

[英]Build error when trying to add Firebase dependency to Qt project

I would like to use Firebase the same way as in any native Android app non using Qt (ie using Java ).我想以与不使用Firebase的任何本机Android应用程序(即使用Java )相同的方式使用Qt I'm already have one (all is working fine).我已经有了一个(一切正常)。

Now I'm trying to add Firebase to my existing Qt project.现在我正在尝试将Firebase添加到我现有的Qt项目中。 For now, I'm trying to add all the required dependencies to build.gradle (so I can use Firebase APIs in my Java source code part of my Qt project), and getting weird errors.现在,我正在尝试将所有必需的依赖项添加到build.gradle (这样我就可以在我的Qt项目的Java源代码部分中使用Firebase APIs ),并出现奇怪的错误。

I'm not good in Gradle so any help is appreciated (if this is possible at all, because I'm using quite old Qt 5.12.12 ).我在Gradle ,因此感谢任何帮助(如果可能的话,因为我使用的是相当旧的Qt 5.12.12 )。

This is build.gradle I have (builds and runs fine):这是我拥有的build.gradle (构建并运行良好):

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
    }
}

repositories {
    google()
    jcenter()
}

apply plugin: 'com.android.application'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'com.google.code.gson:gson:2.7'
    implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
    implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}

android {
    /*******************************************************
     * The following variables:
     * - androidBuildToolsVersion,
     * - androidCompileSdkVersion
     * - qt5AndroidDir - holds the path to qt android files
     *                   needed to build any Qt application
     *                   on Android.
     *
     * are defined in gradle.properties file. This file is
     * updated by QtCreator and androiddeployqt tools.
     * Changing them manually might break the compilation!
     *******************************************************/

    // Buggy thing: fails to build. Needs to be replaced with actual numbers.
    // https://stackoverflow.com/a/46290586/3765267
    /*compileSdkVersion androidCompileSdkVersion.toInteger()
    buildToolsVersion androidBuildToolsVersion*/
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
            aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
            res.srcDirs = [qt5AndroidDir + '/res', 'res']
            resources.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
       }
    }

    lintOptions {
        abortOnError false
    }
}

This is build.gradle with all the dependencies I try to add (I've added classpath 'com.google.gms:google-services:4.3.14' to dependencies section and apply plugin: 'com.google.gms.google-services' line):这是build.gradle ,其中包含我尝试添加的所有依赖项(我已将classpath 'com.google.gms:google-services:4.3.14'添加到dependencies项部分并apply plugin: 'com.google.gms.google-services'线):

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

repositories {
    google()
    jcenter()
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'com.google.code.gson:gson:2.7'
    implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
    implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}

android {
    /*******************************************************
     * The following variables:
     * - androidBuildToolsVersion,
     * - androidCompileSdkVersion
     * - qt5AndroidDir - holds the path to qt android files
     *                   needed to build any Qt application
     *                   on Android.
     *
     * are defined in gradle.properties file. This file is
     * updated by QtCreator and androiddeployqt tools.
     * Changing them manually might break the compilation!
     *******************************************************/

    // Buggy thing: fails to build. Needs to be replaced with actual numbers.
    // https://stackoverflow.com/a/46290586/3765267
    /*compileSdkVersion androidCompileSdkVersion.toInteger()
    buildToolsVersion androidBuildToolsVersion*/
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
            aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
            res.srcDirs = [qt5AndroidDir + '/res', 'res']
            resources.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
       }
    }

    lintOptions {
        abortOnError false
    }
}

And now I'm getting the following weird error trying to build the project:现在我在尝试构建项目时遇到以下奇怪的错误:

Generating Android Package
  Input file: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-libfdm.so-deployment-settings.json
  Output directory: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-build/
  Application binary: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/bin/libfdm.so
  Android build platform: android-33
  Install to device: No

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Work\Source\build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug\ui\android-build\build.gradle' line: 18

* What went wrong:
A problem occurred evaluating root project 'android-build'.
> ASCII

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

Addition #1.添加#1。 I can build using Qt 6.4.1 + Firebase. The question is about Qt 5.12.12.我可以使用 Qt 6.4.1 + Firebase 进行构建。问题是关于 Qt 5.12.12。 I suspect the reason is too old Gradle version it's using (4.6) or something like that.我怀疑原因是它使用的 Gradle 版本太旧 (4.6) 或类似版本。

By default in android we declare the plugin dependencies in gradle root module.默认情况下,在 android 中,我们在 gradle 根模块中声明插件依赖项。 Seems like in qt project we have only one flat layer with only one build.gradle file.似乎在 qt 项目中我们只有一个平面层,只有一个build.gradle文件。 The good news is that we can declare plugin dependencies in settings.gradle as well好消息是我们也可以在settings.gradle中声明插件依赖

Make sure you connected the plugin in settings.gradle :确保您在settings.gradle中连接了插件:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }

    plugins {
        id 'com.android.application' version '7.3.1' apply false
        id 'com.google.gms.google-services' version '4.3.10' apply false
    }
}

now you can apply the plugins in build.gradle like this:现在您可以像这样在build.gradle中应用插件:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
} 

android { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在 flutter 项目中添加对 google_fonts 的依赖时出错 - Error in trying to add dependency for google_fonts in flutter project 尝试将图像上传到 Firebase 存储时出错 - Error when trying to upload images to Firebase storage 尝试将项目连接到 firebase 时 kotlin 的不兼容版本 - incompatibile version of kotlin when trying to connect project to firebase 尝试在 firebase 中使用 google 对用户进行身份验证时出错 - Error when trying to authenticate users with google in firebase 尝试运行 firebase 仿真器时出现 Java 错误 - Java error when trying to run firebase emulators 尝试在我的 Android 应用程序项目中添加电话身份验证时出现错误 - I am getting error when trying to add phone authentication in my Android app project 尝试使用 Ionic4 和 Angular 6 将文档添加到 firebase 时出错 - 错误:PERMISSION_DENIED:权限被拒绝 - Getting error when trying to add document to firebase using Ionic4 and Angular 6 - Error: PERMISSION_DENIED: Permission denied 尝试将图像上传到 firebase (Swift) 时出错 - Getting an error when trying to upload image to firebase (Swift) Flutter/Dart/firebase:: 尝试注销时出错 - Flutter/Dart/firebase:: Error when trying to sign out Flutter,错误,在应用程序中添加数据时,firebase - Flutter, error, when add data in app , firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM