java - Android Studio 编译可执行 jar
PHP中文网
PHP中文网 2017-04-18 10:25:33
0
2
536

用android-studio 写了一个java application,依赖了fastjson,打包成jar的时候发现 fastjson没有导出,导致了 :
java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSONObject

android-studio 中配置Artifacts的功能好像被阉割了,所以能不能用gradle配置,实现打包的时候导出 fastjson 依赖。

ps:项目中同时又Android 和 Java,改用 idea有点不方便(我知道idea也能开发Android)

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
大家讲道理

Later I wrote the task myself and realized this function

jar {
    String someString = ''
    configurations.runtime.each {someString = someString + " lib//"+it.name}
    manifest {
        attributes 'Main-Class': 'cc.gnaixx.tools.core.Hidex'
        attributes 'Class-Path': someString
    }
}

task clearPj(type:Delete){
    delete 'build','target'
}

//copy 运行时依赖
task copyJar(type:Copy){
    from configurations.runtime
    into ('build/libs/lib')
}

task release(type: Copy,dependsOn: [build,copyJar]) {
    //
}
迷茫

Depend on fastjson in the build.gradle file in the project that relies on this jar, such as

dependencies {
    compile 'com.alibaba:fastjson:1.2.13'
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!