【问题标题】:creating android library on jitpack error在 jitpack 错误上创建 android 库
【发布时间】:2021-06-28 20:43:12
【问题描述】:

我正在关注教程:https://medium.com/@anujguptawork/how-to-create-your-own-android-library-and-publish-it-750e0f7481bf

创建安卓库。一切正常,但是当我去 Jitpack 时,“LOG”下的脚本是红色的。这意味着有错误,我无法在 android 项目中使用 m 库。

当我打开它时,脚本是这样说的:

Build starting...
Start: Thu Apr 1 20:33:20 UTC 2021 186300955b87
Git:
1.0.3-0-ga8b71cf
commit a8b71cf19b5b42e08f044d3ede72dd6475e54908
Author: HaroDev 
Date:   Thu Apr 1 22:32:08 2021 +0200

Update settings.gradle


Found Android manifest
Android SDK version: 30. Build tools: 30.0.3
Installing Android platform 30
Installing Build-tools 30.0.3 
Found gradle
Gradle build script
Found gradle version: 6.8.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-6.8-bin.zip
.10%.20%.30%.40%.50%.60%.70%.80%.90%.100%

------------------------------------------------------------
Gradle 6.8
------------------------------------------------------------

Build time:   2021-01-08 16:38:46 UTC
Revision:     b7e82460c5373e194fb478a998c4fcfe7da53a7e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_252 (Private Build 25.252-b09)
OS:           Linux 4.18.0-25-generic amd64

0m3.382s
Getting tasks: ./gradlew tasks --all
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jitpack/build/build.gradle' line: 2

* What went wrong:
Plugin [id: 'com.android.library'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)

* 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 2s
Tasks: 

WARNING:
Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
See the documentation and examples: https://jitpack.io/docs/

Adding android plugin
Adding maven plugin
Found android library build file in .
Running: ./gradlew clean -Pgroup=com.github.HaroDeveloper -Pversion=1.0.3 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jitpack/build/build.gradle' line: 81

* What went wrong:
Could not compile build file '/home/jitpack/build/build.gradle'.
> startup failed:
  build file '/home/jitpack/build/build.gradle': 81: all buildscript {} blocks must appear before any plugins {} blocks in the script
  
  See https://docs.gradle.org/6.8/userguide/plugins.html#sec:plugins_block for information on the plugins {} block
  
   @ line 81, column 1.
     buildscript {
     ^
  
  1 error


* 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 488ms
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
2021-04-01T20:33:55.548468308Z
Exit code: 0

ERROR: No build artifacts found

这是我的 build.gradle:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '6.8'
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

有谁知道如何解决这个问题?

【问题讨论】:

  • 请为您的 sdk 添加您的 gradle 文件
  • @Cliff 好的,我做到了
  • 请添加插件 { id 'com.android.library' id 'kotlin-android' id 'android-maven' }
  • @Cliff 是的,我将它添加到我的构建 gradle 中,但没有任何改变

标签: android kotlin jitpack


【解决方案1】:

出了什么问题:在以下任何来源中都找不到插件 [id: 'com.android.library']:

你应该在下面使用

plugins {
    id 'com.android.library'
    id 'android-maven'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

仅供参考

确保该库列在您的 settings.gradle 文件的顶部,如下所示的名为 "testLib" 的库:

include ':app', ':testLib'

然后打开app模块的build.gradle文件,在依赖块中添加新行,如下sn-p所示:

dependencies {
    implementation project(":testLib")
}

【讨论】:

  • 你的意思是把它添加到我的 build.gradle 中?我做到了,但没有任何改变,同样的错误仍然存​​在......
  • 我只是把它变红了,但我真的看不出与我用来制作库的教程中的不同。我查看了一些不同的地方 f.e (youtube.com/…),但它们都和我做的一样,但对于这些地方来说它是有效的。我有截止日期完成这个直到星期二需要找到解决方案直到...
  • @Kratos 似乎草率的错误会让你付出代价。如果解决了请告诉我。
  • 我修好了。我的错误是我只在没有项目的情况下将库推送到 github。我错误地认为我不需要项目,而只需要库来工作。感谢您的协助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
  • 2018-01-17
  • 1970-01-01
  • 1970-01-01
  • 2018-04-28
  • 2023-04-02
  • 1970-01-01
相关资源
最近更新 更多