首页 > 解决方案 > 如何从命令行(Ubuntu 18.04,失败:错误的插件选项格式)构建这个 gradle 项目(KotlinParcelize)?

问题描述

我发现这篇文章:https ://android.jlelse.eu/yet-another-awesome-kotlin-feature-parcelize-5439718ba220 - 我想看看那里的代码,https://github.com/burakeregar/KotlinParcelize .

我正在使用 Ubuntu 18.04,我想./gradlew在终端中运行。

我的 Android SDK 目录在/path/to/adt-bundle-linux-x86-20140321/sdk...

所以我做了:

$ cd /tmp
$ git clone https://github.com/burakeregar/KotlinParcelize.git KotlinParcelize_git
Cloning into 'KotlinParcelize_git'...
remote: Enumerating objects: 75, done.
remote: Total 75 (delta 0), reused 0 (delta 0), pack-reused 75
Unpacking objects: 100% (75/75), done.
$ cd KotlinParcelize_git/
$ ./gradlew assembleDebug
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip
.....................................................................
Unzipping //home/user/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew/gradle-4.1-all.zip to //home/user/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew
Set executable permissions for: //home/user/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew/gradle-4.1/bin/gradle

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '11.0.8'.

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

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

嗯,这是一个Java问题;我的默认是 java 11,但我也有 java 8,所以试试:

$ apt-show-versions -r openjdk | grep uptodate
openjdk-11-jre:amd64/bionic-security 11.0.8+10-0ubuntu1~18.04.1 uptodate
openjdk-11-jre-headless:amd64/bionic-security 11.0.8+10-0ubuntu1~18.04.1 uptodate
openjdk-8-jdk:amd64/bionic-security 8u265-b01-0ubuntu2~18.04 uptodate
openjdk-8-jdk-headless:amd64/bionic-security 8u265-b01-0ubuntu2~18.04 uptodate
openjdk-8-jre:amd64/bionic-security 8u265-b01-0ubuntu2~18.04 uptodate
openjdk-8-jre-headless:amd64/bionic-security 8u265-b01-0ubuntu2~18.04 uptodate

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

好的,再试一次:

$ ./gradlew assembleDebug

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

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

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

BUILD FAILED in 0s

对,所以我这样做:

$ echo sdk.dir=/path/to/adt-bundle-linux-x86-20140321/sdk > local.properties 

好的,再试一次:

$ ./gradlew assembleDebug

> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
Observed package id 'build-tools;19.0.3' in inconsistent location '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/android-4.4.2' (Expected '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/19.0.3')
Checking the license for package Android SDK Build-Tools 26.0.2 in /path/to/adt-bundle-linux-x86-20140321/sdk/licenses
Warning: License for package Android SDK Build-Tools 26.0.2 not accepted.


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 26.0.2].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

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

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

BUILD FAILED in 1s

好的,所以我运行/path/to/adt-bundle-linux-x86-20140321/sdk/tools/android,安装 Build-Tools 26.0.2(显然是 repo 中 gradle 版本的最低版本,以及我以前没有的那些构建工具),再试​​一次:

$ git add -f local.properties # so it does not get deleted by git clean

$ git clean -dxf

$ ./gradlew --stop
Stopping Daemon(s)
1 Daemon stopped

$ ./gradlew assembleDebug
Starting a Gradle Daemon, 5 stopped Daemons could not be reused, use --status for details

> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
Observed package id 'build-tools;19.0.3' in inconsistent location '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/android-4.4.2' (Expected '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/19.0.3')
Observed package id 'build-tools;19.0.3' in inconsistent location '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/android-4.4.2' (Expected '/path/to/adt-bundle-linux-x86-20140321/sdk/build-tools/19.0.3')

e: Wrong plugin option format: null, should be plugin:<pluginId>:<optionName>=<value>

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

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

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

BUILD FAILED in 10s
12 actionable tasks: 12 executed

如果你运行./gradlew assembleDebug --debug,你会得到大约 6400 多行的大量日志,我将其粘贴在这里:KotlinParcelize_gradlew_debug.log,唯一相关的部分似乎是:

...
12:05:09.468 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: accepted socket from [127.0.0.1:26356]
12:05:09.469 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 80
12:05:09.469 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "[Ljava.rmi.server.ObjID;", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.469 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.rmi.server.ObjID", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.470 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.rmi.server.UID", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.470 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.rmi.dgc.Lease", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.472 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.rmi.dgc.VMID", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.473 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "[B", codebase = "", defaultLoader = sun.misc.Launcher$ExtClassLoader@3d7dbe2d
12:05:09.488 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 82
12:05:09.488 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 80
12:05:09.521 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 82
12:05:09.526 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 80
12:05:09.526 [ERROR] [org.gradle.api.Task] e: Wrong plugin option format: null, should be plugin:<pluginId>:<optionName>=<value>
12:05:09.532 [DEBUG] [sun.rmi.transport.tcp] RMI TCP Connection(2)-127.0.0.1: (port 1757) op = 80
12:05:09.533 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "org.jetbrains.kotlin.daemon.report.CompileIterationResult", codebase = ""
12:05:09.533 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.util.LinkedHashSet", codebase = ""
12:05:09.533 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.util.HashSet", codebase = ""
12:05:09.533 [DEBUG] [sun.rmi.loader] RMI TCP Connection(2)-127.0.0.1: name = "java.io.File", codebase = ""
12:05:09.534 [DEBUG] [org.gradle.api.Project] [KOTLIN] compile iteration: app/src/main/java/com/burakeregar/kotlinparcelize/MainActivity.kt, app/src/main/java/com/burakeregar/kotlinparcelize/PersonModel.kt, app/src/main/java/com/burakeregar/kotlinparcelize/SecondActivity.kt
...

...但我仍然无法理解 - “错误的插件选项格式”中的插件是什么?

好吧,我被困在这里....我怎样才能编译这个例子?


编辑:我发现的几件事:

标签: javaandroidkotlingradle

解决方案


好吧,终于用Android Studio 4.0.1打开了项目,并且:

  • 将项目中的 gradle 更新到 6.1.1(从原来的 4.1)
  • ext.kotlin_version = '1.3.72'从 1.2.0更新
  • 使用 kotlin-stdlib-jdk7 而不是 kotlin-stdlib-jre7 (因为我在某处收到了弃用消息)

......现在我不再得到“错误的插件选项格式” - 但现在我得到“类'PersonModel'不是抽象的并且没有实现抽象成员公共抽象......” - 我会问一个新的关于问题。


推荐阅读