0

簡単なチュートリアルを見つけようとしています: gbps を使用して Android 用の簡単なアプリケーションを作成する方法。次のリンクが見つかりました。

  1. スタック oferflow。cbs のバージョンは既に 1.11 に更新されており、android のサポートが含まれていますが、この質問に対する回答は得られていません。
  2. QBS ドキュメンテーションの AndroidApk 項目。この場合、次の警告が表示されます。'../Application/src/main/AndroidManifest.xml' does not exist.

残念ながら新しい情報は見つかりませんでした。私は助けを求めます。

更新: Qmake の場合、次のような標準のウィジェット プロジェクトを作成するだけです。

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = androidtest
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

CONFIG += mobility
MOBILITY = 

そして、これは機能し、うまく構築されます。QtCreator は必要なすべてのファイルを自動的に作成し、電話でアプリを実行します

Qbs では、同じアプリケーションを作成しようとしています。このため、QBS ファイルがあります。

import qbs

Project {
    CppApplication {
        name: "helloworld"

        Depends {
            name: "Qt"
            submodules: [
                "core",
                "widgets"
            ]
        }

        Depends { name: "Android.ndk" }
        Android.ndk.appStl: "gnustl_shared"

        Group {
            name: "src"
            files: [
                "main*.*"

            ]
        }
    }

    AndroidApk {
        name: "helloworld_android"
        Depends {name: "helloworld" }
        packageName: "com.example.android.helloworld"
    }
}

最後に、HelloWorld 製品 (libhelloworld.so) を使用しました。しかし、「helloworld_android」の最初のエラーは、android マニフェストでの失敗です。このファイルは未定義です。次に何をすべきですか?

4

3 に答える 3

0

わかりました、私はそれを作ったと思います。それは良い解決策ではありませんが、これは仕事です。結果の APK は、「\install-root\$productName$\build\outputs\apk\$productName$-debug.apk にあります。

import qbs
import qbs.TextFile
import qbs.Process
import qbs.File

Project {
    //Main Application
    CppApplication {
        name: "helloworld";

        Depends {
            name: "Qt"
            submodules: [
                "core",
                "widgets"
            ]
        }

        Depends { name: "Android.ndk" }
        Android.ndk.appStl: "gnustl_shared"

        Group {
            name: "src"
            files: [
                "main*.*"
            ]
        }
        Group {
            qbs.install: true
            fileTagsFilter: "dynamiclibrary"
            qbs.installPrefix : product.name+"/libs/"+Android.ndk.abi+"/"
        }
    }

    //Preparation
    Product {
        name: "Prepared2Deploy"
        type: "prepared2deploy"
        Depends { name: "helloworld" }
        Depends { name: "Qt.core" }
        Depends { name: "Android.ndk" }
        Depends { name: "Android.sdk" }
        Rule {
            inputsFromDependencies: "installable"
            Artifact {
                filePath: input.fileName+".json"
                fileTags: "prepared2deploy"
            }
            prepare: {
                var cmd = new JavaScriptCommand();
                cmd.description = "prepare for androidDeployQt";
                cmd.highlight = "install";
                cmd.sourceCode = function() {
                    var outputFile = new TextFile(output.filePath, TextFile.WriteOnly);
                    outputFile.writeLine("{");
                    outputFile.writeLine("     \"qt\": \"" + product.Qt.core.binPath.replace(/\/bin$/,"") + "\",");
                    outputFile.writeLine("     \"sdk\": \"" + product.Android.sdk.sdkDir + "\",");
                    outputFile.writeLine("     \"sdkBuildToolsRevision\": \"" + product.Android.sdk.buildToolsVersion + "\",");
                    var ndkDir = product.Android.ndk.ndkDir.replace(/\\/g,"/"); //why sdk ndk get wrong slashes?
                    outputFile.writeLine("     \"ndk\": \""+ndkDir+"\",");
                    var toolchain =  product.cpp.toolchainPrefix.replace(/-$/,"");
                    outputFile.writeLine("     \"toolchain-prefix\": \"" + toolchain + "\",");
                    outputFile.writeLine("     \"tool-prefix\": \"" + toolchain + "\",");
                    outputFile.writeLine("     \"toolchain-version\": \"4.9\",");   //how I can get it ???
                    outputFile.writeLine("     \"ndk-host\": \"windows-x86_64\","); //how I can get it ???
                    var abi = product.Android.ndk.abi
                    outputFile.writeLine("     \"target-architecture\": \""+abi+"\",");
                    outputFile.writeLine("     \"stdcpp-path\": \""+ndkDir+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + //how I can get it ???
                                         abi+"/lib"+product.Android.ndk.appStl+".so\",");
                    outputFile.writeLine("     \"application-binary\": \""+ input.filePath+"\"");
                    outputFile.writeLine("}");
                    outputFile.close();
                }
                return cmd;
            }
        }
    }
    //Deployer
    Product {
        name: "AndroidDeployQt"
        Depends { name: "helloworld" }
        id: androidDeployQt
        type: "androidDeployQt"
        Depends {name: "Qt.core" }

        Rule {
            inputsFromDependencies: "prepared2deploy"
            alwaysRun: true
            Artifact {
                filePath: "log.txt"
                fileTags: "androidDeployQt"
            }
            prepare: {
                var cmd = new JavaScriptCommand();
                cmd.description = "androidDeployQt";
                cmd.highlight = "install";
                cmd.sourceCode = function() {
                    var logFile = new TextFile(output.filePath, TextFile.WriteOnly);
                    logFile.writeLine(input.fileName);
                    var productName = input.fileName.replace(/.so.json$/,"").replace(/^(lib)/,"");
                    var androidDeployProcess = new Process();
                    var exitCode = androidDeployProcess.exec(product.Qt.core.binPath+"/androiddeployqt.exe",
                                                             [
                                                                 "--input", input.filePath,
                                                                 "--output", project.buildDirectory+"/install-root/"+productName,
                                                                 "--android-platform", "android-25", //???
                                                                 "--gradle"
                                                             ])
                    if (exitCode) {
                        console.error("Error at androidDeployProcess. Error code: "+exitCode);
                        console.error(androidDeployProcess.readStdErr());
                        console.error("FULL_LOG: ");
                        console.error(androidDeployProcess.readStdOut());
                    }
                    logFile.close();
                }
                return cmd;
            }
        }
    }
}
于 2018-07-20T14:36:27.563 に答える