【已解決】上傳專案到binary 上面的時候報錯:FAILURE: Build failed with an exception.
zhangyinshandeMacBook-Pro:BaseLibs zhangyinshan$ ./gradlew install
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/zhangyinshan/Documents/android/BaseLibs/app/build.gradle' line: 75
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method install() for arguments [
* 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 1s
原因:plugin 沒有起作用引起的
解決辦法:
1: 需要在project 的gradle 裡面新增:
//下面這兩句
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' //下面這兩句 classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
2: 需要在module 裡面新增如下兩句:
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
//專案主頁https://github.com/kodulf/BaseLibs
def siteUrl = 'https://github.com/kodulf/BaseLibs'
//專案的git地址
def gitUrl = 'https://github.com/kodulf/BaseLibs.git'
//釋出到JCenter上的專案名字
def libName = "Baselibs"
//釋出到組織名稱名字,必須填寫
group = "com.kodulf.BaseLibs"
// 版本號,下次更新是隻需要更改版本號即可
version = "1.0.1"
//上面配置後上傳至JCenter後的編譯路徑是這樣的: compile 'me.songning.CircleView:library:1.0.0'
//生成原始檔
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
//生成Javadoc文件
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
//文件打包成jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
//拷貝javadoc檔案
task copyDoc(type: Copy) {
from "${buildDir}/docs/"
into "docs"
}
//上傳到JCenter所需要的原始碼檔案
artifacts {
archives javadocJar
archives sourcesJar
}
// 配置maven庫,生成POM.xml檔案
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
//專案描述,隨意填
name 'An android utils libs.'
url siteUrl
licenses {
license {
//開源協議
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
//開發者的個人資訊
id 'kodulf'
name 'kodulf'
email '[email protected]'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
//上傳到JCenter
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user") //讀取 local.properties 檔案裡面的 bintray.user
key = properties.getProperty("bintray.apikey") //讀取 local.properties 檔案裡面的 bintray.apikey
configurations = ['archives']
pkg {
//這裡的repo值必須要和你建立Maven倉庫的時候的名字一樣
repo = "Baselibs"
//釋出到JCenter上的專案名字
name = libName
//專案描述
desc = 'An android utils libs'
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
javadoc {
options {
//如果你的專案裡面有中文註釋的話,必須將格式設定為UTF-8,不然會出現亂碼
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/7/docs/api"
}
}