首页 > 解决方案 > Gluon Mobile:使用 ExoPlayer

问题描述

我正在使用 GluonMobile 开发一个 android 应用程序。对于一个功能,我需要一个 ExoPlayer。所以我包含了依赖项 com.google.android.exoplayer:exoplayer:+ 。似乎依赖是一个 aar 文件,而 InteliJ 找不到任何 ExoPlayers 类。这是我的构建脚本:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
        maven {
            url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
        }
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:+'

        classpath 'com.github.jengelman.gradle.plugins:shadow:+'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'idea'

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

repositories {
    mavenCentral()
    jcenter()
    google()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
    maven {
        url uri('libs')
    }
}

mainClassName = '[...].main.Main'
version = '2.0_Alpha'

dependencies {
    compile "com.gluonhq:charm:+"
    compile "com.gluonhq:glisten-afterburner:+"

    compile "com.google.apis:google-api-services-youtube:+"
    compile "com.google.api-client:google-api-client-java6:+"
    compile "com.google.oauth-client:google-oauth-client-jetty:+"
    compile "com.google.code.gson:gson:+"
    compileOnly 'lib.idea:annotations:0'

    androidImplementation "org.javafxports:jfxdvk:+"

    androidImplementation 'com.google.android.exoplayer:exoplayer:+@aar'
}

jfxmobile {
    downConfig {
        version = '+'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        //noinspection GroovyAssignabilityCheck
        plugins 'browser', 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
        //androidSdk = "${ANDROID_HOME}"
        compileSdkVersion = 28
        targetSdkVersion = 22
        minSdkVersion = 16


        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }
    }
}

task installApk{
    group = "gluon mobile for android"
    doLast{
        exec {
            workingDir "${ANDROID_HOME}\\platform-tools"
            commandLine "${workingDir}\\adb.exe", "install", "${buildDir}/javafxports/android/YouJavaTubeApp.apk"
        }
    }
}

我已经发现了一些关于 explodeAarDependencies(...) 的东西,但它没有用。所以有人知道如何将(任何)aar 依赖项包含到我的 GluonMobile 项目中。

感谢您的帮助。

标签: androidgradlegluon-mobilejavafxports

解决方案


你在正确的轨道上explodeAarDependencies,这是 jfxmobile 插件用来将 .aar 依赖项解压到 .jar 和其他资源中的任务。

您可以在此处找到有关该任务的信息。

如何使用它:

在您的 build.gradle 文件中,包含依赖项:

dependencies {
    ...

    androidCompile 'com.google.android.exoplayer:exoplayer:2.9.0'
}
  • 注意1:不要使用@aar

  • 注意 2:jfxmobile 插件使用一些已定义的配置,例如androidCompile代替androidImplementation.

  • 注意 3:我宁愿使用给定的版本,而不是+.

并在文件末尾添加任务:

project.afterEvaluate {
    explodeAarDependencies(project.configurations.androidCompile)
}

就是这样。

保存并应用/同步/重新加载构建,您应该会看到exoplayerAndroid 编译依赖项中包含一堆传递依赖项,包括 .aar 和 .jar 文件。


推荐阅读