关于自己写的aar包发布到maven过程中的一些问题解决

很多开发者都想自己写一套好用的框架,发布出去给别人引用,自从android studio问世以来,不断的改进,关于引用他人的成果非常方便简单了,用过android studio的用户都知道,在build.gradle中引用只需添加一句代码:
 compile 'com.android.support:appcompat-v7:24.1.1'
 是不是非常简单?比以往的下载jar包,拷贝到项目是不是简单多了?那么,我写好了一套非常好用的代码,我也想分享出去给别人用,让别人也能在build.gradle按照上面的类型添加一句代码,就可以直接使用,我该怎么做呢?具体怎么做,可以参考这篇博客,是他教会了我的。
[博客](http://blog.csdn.net/lmj623565791/article/details/51148825)
根据这篇博客,我就马上跟着hongyang大神操作。
(1)注册bintray.com账号,获取api key.(可参考上面的hongyang博客)
 (2)引入bintray-release

在第2步的过程中,遇到了一些小麻烦,我先把对应代码贴下
1.在项目的build.gradle文件中添加bintray-release的classpath
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        //添加的classpath
        classpath 'com.novoda:bintray-release:0.3.4'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
2.在要给他人引用的module下的build.gradle下添加如下代码:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用户名
    groupId = 'com.example.fragmentstack'//jcenter上的路径
    artifactId = 'fragmentstack'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/huangxuanheng/ishowProject'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
}
好了,接下来就是运行下面代码:
gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx  -PdryRun=false

的时候,遇到了一些问题,问题如下:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
...

* Try:        
Run with --debug option to get more log output.

我一看,马上copy这句话:

android {
    lintOptions {
        abortOnError false
    }
}

到我的module对应的build.gradle里面,copy过来后的代码如下:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //添加的那段报错代码
    lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用户名
    groupId = 'com.example.fragmentstack'//jcenter上的路径
    artifactId = 'fragmentstack'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/hyman/basetools'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
}

继续运行gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx -PdryRun=false
还是报那个错误,我非常的纳闷,一步一步的检查,认为自己已经添加进去了,可是无论我怎么运行,总之还是报这个错误,我非常的郁闷与无助,于是,我就开始了百度,经过了九九八十一难,终于找到了一篇比较类似我的文章,不记得那篇文章是哪个大神写的了,但根据他写的内容,关于该问题,我得到了解决。其实是我忽略了一点,我虽然添加了这段代码

 lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

到要分享的module对应的build.gradle,但一个项目中还有其他的module,然而其他的module我并没有添加,我以为其他不添加也不会有什么影响,我错了,问题就出在这里。
于是,我在所有的module对应的build.gradle中,都添加了这几行代码:

 lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }
然后同步项目后运行:
gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx  -PdryRun=false
发现上面的问题解决了,不再报那错误了,但还是出现了新的错误,错误内容大概如下:
Could not create package 'huangxuanheng/maven/fragmentstack': HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]
这个错误的大概意思是,在我注册的bintray.com账号里面的maven没有找到
于是我又苦逼的找资料,我[在这](http://blog.csdn.net/small_lee/article/details/52328613)
找到了答案,原来是我注册的bintray.com账号里面,没有建有maven项目,于是就根据[文章](http://blog.csdn.net/small_lee/article/details/52328613)去建我的maven项目,建好了之后,在我的要分享的module对应build.gradle里面,把artifactId修改为我在maven中建的项目,改完后的大致代码如下:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用户名
    groupId = 'com.example.fragmentstack'//jcenter上的路径
    artifactId = 'ishow'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/huangxuanheng/ishowProject'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
}

改好后,继续运行:gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx -PdryRun=false
惊奇的发现,竟然BUILD SUCCESS。于是我马上去我的bintray.com账号里面看,果然成功发布到了maven项目里面
我的这些问题的解决,离不开大神们的贡献,在此,非常感谢一直默默贡献的大神们,谢谢你们

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
发布本地 AAR ,您需要完成以下步骤: 1. 在您的项目根目录的 `build.gradle` 文件添加 Maven 插件: ``` plugins { id 'maven-publish' } ``` 2. 配置发布信息。在 `build.gradle` 文件添加以下内容: ``` group = 'com.example' // 填您想要发布的 Group ID version = '1.0.0' // 填您想要发布的版本号 publishing { publications { MyPublication(MavenPublication) { artifact file('path/to/your/aar/file') // 填您想要发布AAR 的路径 groupId group version version artifactId 'your-library-name' // 填您想要发布的 Artifact ID pom.withXml { // 填您想要发布的信息 def dependenciesNode = asNode().appendNode('dependencies') def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', 'com.example') dependencyNode.appendNode('artifactId', 'example-library') dependencyNode.appendNode('version', '1.0.0') } } } repositories { mavenLocal() //配置本地 maven 仓库 } } ``` 注意:在 `pom.withXml` ,您需要填您想要发布的信息,例如依赖项等。 3. 运行 `./gradlew publish` 命令,Gradle 将会发布您的 AAR 到本地 Maven 仓库。如果您需要发布到其他 Maven 仓库,请将 `mavenLocal()` 替换为其他 Maven 仓库 URL。 4. 如果您的 AAR 依赖其他库,您需要将这些库发布到本地仓库或其他 Maven 仓库,否则其他开发者在使用您的 AAR 时会出现依赖错误。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值