Android Studio library发布JCenter编码错误_编码GBK的不可映射字符!

原文地址:http://blog.csdn.net/maxdavid/article/details/46710083

在此感谢帮助过我的楼主:

最近想把一个Android Studio下的Library发布到JCenter,运行bintrayUpload时出现了“编码GBK的不可映射字符”的错误。

估计是编码的错误,百度“android studio 编码GBK的不可映射字符”的解决办法是将如下代码添加到Library目录下的build.gradle文件中:

  1. tasks.withType(Compile) {  
  2.     options.encoding = "UTF-8"  
加入上面代码后,gradle构建项目时还是出现一样的错误,添加 options.encoding = "UTF-8" 到 task javadoc 中,如下:

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    options.encoding = "UTF-8"
}
library下的build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "2.0.1"

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        versionName project.VERSION_NAME
        versionCode Integer.parseInt(project.VERSION_CODE)
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions{
        abortOnError false
    }

}

def siteUrl = 'https://github.com/hongyangAndroid/okhttp-utils' 
def gitUrl = 'https://github.com/hongyangAndroid/okhttp-utils.git'      

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'okhttputils'                                   // #CONFIG# // project title
                url siteUrl
                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'hongyangAndroid'                                        
                        name 'ZhangHongyang'                                     
                        email '623565791@qq.com'                               
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}
tasks.withType(JavaCompile) {
    options.encoding = "utf-8"
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    options.encoding = "UTF-8"
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    configurations = ['archives']
    pkg {
        repo = "maven"
        name = "okhttputils"                                                 // #CONFIG# project name in jcenter
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}


//定义一个函数,target是生成jar包的文件名,classDir是class文件所在的文件夹
def makeJar(String target,String classDir){
    exec{
        executable "jar"   //调用jar
        args "cvf",target
        args "-C", classDir
        args "","."


    }
}

//新建一个task,名为buildLib,依赖build(build是一个自带的task)
task buildLib(dependsOn:['build'])<< {
    makeJar("okhttputils.jar","build/intermediates/classes/release")
}

task clearJar(type: Delete) {
    delete 'build/outputs/okhttputils.jar'
}

task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('build/outputs/')
    include('classes.jar')
    rename ('classes.jar', 'okhttputils.jar')
}

makeJar.dependsOn(clearJar, build)



dependencies {
    compile  'com.squareup.okhttp:okhttp:2.7.2'
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值