コード例 #1
0
ファイル: androidmanager.cpp プロジェクト: choenig/qt-creator
bool AndroidManager::updateGradleProperties(ProjectExplorer::Target *target)
{
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
    if (!version)
        return false;

    AndroidQtSupport *qtSupport = androidQtSupport(target);
    if (!qtSupport)
        return false;

    Utils::FileName packageSourceDir = qtSupport->packageSourceDir(target);
    if (!packageSourceDir.appendPath("gradlew").exists())
        return false;

    Utils::FileName wrapperProps = packageSourceDir;
    wrapperProps.appendPath(QLatin1String("gradle/wrapper/gradle-wrapper.properties"));
    if (wrapperProps.exists()) {
        GradleProperties wrapperProperties = readGradleProperties(wrapperProps.toString());
        QString distributionUrl = QString::fromLocal8Bit(wrapperProperties["distributionUrl"]);
        // Update only old gradle distributionUrl
        if (distributionUrl.endsWith(QLatin1String("distributions/gradle-1.12-all.zip"))) {
            wrapperProperties["distributionUrl"] = "https\\://services.gradle.org/distributions/gradle-2.2.1-all.zip";
            mergeGradleProperties(wrapperProps.toString(), wrapperProperties);
        }
    }

    GradleProperties localProperties;
    localProperties["sdk.dir"] = AndroidConfigurations::currentConfig().sdkLocation().toString().toLocal8Bit();
    if (!mergeGradleProperties(packageSourceDir.appendPath("local.properties").toString(), localProperties))
        return false;

    QString gradlePropertiesPath = packageSourceDir.appendPath("gradle.properties").toString();
    GradleProperties gradleProperties = readGradleProperties(gradlePropertiesPath);
    gradleProperties["qt5AndroidDir"] = version->qmakeProperty("QT_INSTALL_PREFIX")
            .append(QLatin1String("/src/android/java")).toLocal8Bit();
    gradleProperties["buildDir"] = ".build";
    gradleProperties["androidCompileSdkVersion"] = buildTargetSDK(target).split(QLatin1Char('-')).last().toLocal8Bit();
    if (gradleProperties["androidBuildToolsVersion"].isEmpty()) {
        QVersionNumber buildtoolVersion = AndroidConfigurations::currentConfig().buildToolsVersion();
        if (buildtoolVersion.isNull())
            return false;
        gradleProperties["androidBuildToolsVersion"] = buildtoolVersion.toString().toLocal8Bit();
    }
    return mergeGradleProperties(gradlePropertiesPath, gradleProperties);
}
コード例 #2
0
ファイル: qoperatingsystemversion.cpp プロジェクト: RSATom/Qt
QT_BEGIN_NAMESPACE

/*!
    \class QOperatingSystemVersion
    \inmodule QtCore
    \since 5.9
    \brief The QOperatingSystemVersion class provides information about the
    operating system version.

    Unlike other version functions in QSysInfo, QOperatingSystemVersion provides
    access to the full version number that \a developers typically use to vary
    behavior or determine whether to enable APIs or features based on the
    operating system version (as opposed to the kernel version number or
    marketing version).

    This class is also a complete replacement for QSysInfo::macVersion and
    QSysInfo::windowsVersion, additionally providing access to the third (micro)
    version number component.

    Presently, Android, Apple Platforms (iOS, macOS, tvOS, and watchOS),
    and Windows are supported.

    The \a majorVersion(), \a minorVersion(), and \a microVersion() functions
    return the parts of the operating system version number based on:

    \table
        \header
            \li Platforms
            \li Value
        \row
            \li Android
            \li result of parsing
                \l{https://developer.android.com/reference/android/os/Build.VERSION.html#RELEASE}{android.os.Build.VERSION.RELEASE}
                using QVersionNumber, with a fallback to
                \l{https://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT}{android.os.Build.VERSION.SDK_INT}
                to determine the major and minor version component if the former
                fails
        \row
            \li Apple Platforms
            \li majorVersion, minorVersion, and patchVersion from
                \l{https://developer.apple.com/reference/foundation/nsprocessinfo/1410906-operatingsystemversion?language=objc}{NSProcessInfo.operatingSystemVersion}
        \row
            \li Windows
            \li dwMajorVersion, dwMinorVersion, and dwBuildNumber from
                \l{https://msdn.microsoft.com/en-us/library/mt723418.aspx}{RtlGetVersion} -
                note that this function ALWAYS return the version number of the
                underlying operating system, as opposed to the shim underneath
                GetVersionEx that hides the real version number if the
                application is not manifested for that version of the OS
    \endtable

    Because QOperatingSystemVersion stores both a version number and an OS type, the OS type
    can be taken into account when performing comparisons. For example, on a macOS system running
    macOS Sierra (v10.12), the following expression will return \c false even though the
    major version number component of the object on the left hand side of the expression (10) is
    greater than that of the object on the right (9):

    \code
    QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 9)
    \endcode

    This allows expressions for multiple operating systems to be joined with a logical OR operator
    and still work as expected. For example:

    \code
    auto current = QOperatingSystemVersion::current();
    if (current >= QOperatingSystemVersion::OSXYosemite ||
        current >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) {
        // returns true on macOS >= 10.10 and iOS >= 8.0, but false on macOS < 10.10 and iOS < 8.0
    }
    \endcode

    A more naive comparison algorithm might incorrectly return true on all versions of macOS,
    including Mac OS 9. This behavior is achieved by overloading the comparison operators to return
    \c false whenever the OS types of the QOperatingSystemVersion instances being compared do not
    match. Be aware that due to this it can be the case \c x >= y and \c x < y are BOTH \c false
    for the same instances of \c x and \c y.
*/

/*!
    \enum QOperatingSystemVersion::OSType

    This enum provides symbolic names for the various operating
    system families supported by QOperatingSystemVersion.

    \value Android      The Google Android operating system.
    \value IOS          The Apple iOS operating system.
    \value MacOS        The Apple macOS operating system.
    \value TvOS         The Apple tvOS operating system.
    \value WatchOS      The Apple watchOS operating system.
    \value Windows      The Microsoft Windows operating system.

    \value Unknown      An unknown or unsupported operating system.
*/

/*!
    \fn QOperatingSystemVersion::QOperatingSystemVersion(OSType osType, int vmajor, int vminor = -1, int vmicro = -1)

    Constructs a QOperatingSystemVersion consisting of the OS type \a osType, and
    major, minor, and micro version numbers \a vmajor, \a vminor and \a vmicro, respectively.
*/

/*!
    \fn QOperatingSystemVersion QOperatingSystemVersion::current()

    Returns a QOperatingSystemVersion indicating the current OS and its version number.

    \sa currentType()
*/
#if !defined(Q_OS_DARWIN) && !defined(Q_OS_WIN)
QOperatingSystemVersion QOperatingSystemVersion::current()
{
    QOperatingSystemVersion version;
    version.m_os = currentType();
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
#ifndef QT_BOOTSTRAPPED
    const QVersionNumber v = QVersionNumber::fromString(QJNIObjectPrivate::getStaticObjectField(
        "android/os/Build$VERSION", "RELEASE", "Ljava/lang/String;").toString());
    if (!v.isNull()) {
        version.m_major = v.majorVersion();
        version.m_minor = v.minorVersion();
        version.m_micro = v.microVersion();
        return version;
    }
#endif

    version.m_major = -1;
    version.m_minor = -1;

    static const struct {
        uint major : 4;
        uint minor : 4;
    } versions[] = {
        { 1, 0 }, // API level 1
        { 1, 1 }, // API level 2
        { 1, 5 }, // API level 3
        { 1, 6 }, // API level 4
        { 2, 0 }, // API level 5
        { 2, 0 }, // API level 6
        { 2, 1 }, // API level 7
        { 2, 2 }, // API level 8
        { 2, 3 }, // API level 9
        { 2, 3 }, // API level 10
        { 3, 0 }, // API level 11
        { 3, 1 }, // API level 12
        { 3, 2 }, // API level 13
        { 4, 0 }, // API level 14
        { 4, 0 }, // API level 15
        { 4, 1 }, // API level 16
        { 4, 2 }, // API level 17
        { 4, 3 }, // API level 18
        { 4, 4 }, // API level 19
        { 4, 4 }, // API level 20
        { 5, 0 }, // API level 21
        { 5, 1 }, // API level 22
        { 6, 0 }, // API level 23
        { 7, 0 }, // API level 24
        { 7, 1 }, // API level 25
        { 8, 0 }, // API level 26
    };

    // This will give us at least the first 2 version components
    const size_t versionIdx = size_t(QJNIObjectPrivate::getStaticField<jint>(
        "android/os/Build$VERSION", "SDK_INT")) - 1;
    if (versionIdx < sizeof(versions) / sizeof(versions[0])) {
        version.m_major = versions[versionIdx].major;
        version.m_minor = versions[versionIdx].minor;
    }

    // API level 6 was exactly version 2.0.1
    version.m_micro = versionIdx == 5 ? 1 : -1;
#else
    version.m_major = -1;
    version.m_minor = -1;
    version.m_micro = -1;
#endif
    return version;
}