什么叫通用工程,我发布的sdk里面只有一个 同样的jar文件,一个so,而不是给eclipse一个 android studio,这两个开发软件都可以打开这个文件夹,这样demo和sdk 库可以省不少体积。
对于只用eclipse的开发者同样可以打开。
我是喜欢as的,但是客户不跟时代,没办法,我必须得发布eclipse的demo,发arr特么不行,我们公司太惯这群人了,。
Build.gradle内容
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "cn.qssq666.demo"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs=['libs']
assets.srcDirs = ['assets']
}
}
}
dependencies {
api files('libs/fastjson-1.2.7.jar')
implementation files('libs/xxx.jar')
}
eclipse文件内容
引入libs
未完待续
project.properties
target=android-23
android.library.reference.1=../../sdk/xxxx
//或者
android.library=true
local.properties
ndk.dir=D\:\\env\\android_sdk\\ndk-bundle
sdk.dir=D\:\\env\\android_sdk
.classpath
.project
项目名称
com.android.ide.eclipse.adt.ResourceManagerBuilder
com.android.ide.eclipse.adt.PreCompilerBuilder
org.eclipse.jdt.core.javabuilder
com.android.ide.eclipse.adt.ApkBuilder
com.android.ide.eclipse.adt.AndroidNature
org.eclipse.jdt.core.javanature
eclipse 清单文件可能需要的默认值
这个东西在android studio已经是通过build.gradle来弄了,但是这东西没有,
别名的效果
从上图可以看出来localtion是app,但是显示的名字是自定义的。
那么项目整体目录是如下这样的.
版本定义
最后就是res文件夹不能为空,另外eclipse的library不识别资产目录只能看到demo工程。
最后贡献发布sdk的gradle脚本,目前有一个疑问就是 执行删除文件然后立马执行复制会出现失败的情况,目前无法得知原因。
import java.text.SimpleDateFormat
apply plugin: 'com.android.library'
def publishDir = 'D:/luozheng/gradle_sdk/checkAndProtocolPublish1'
def jniDir = "${project.rootDir}/mergeincludearr/build\\intermediates\\jniLibs\\release"
def arrDir = "${project.rootDir}/mergeincludearr/build/outputs/aar/mergeincludearr-release.aar"
def jarDir = "${project.rootDir}/mergeincludearr/build\\intermediates\\intermediate-jars\\release/classes.jar"
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
android {
lintOptions {
abortOnError false
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
aidl.srcDirs = ['src']
def temp = ['envcheck/java', 'simulator/java']
if (BAIHE_SDK) {
temp.add('proxyencryptsms/java')
} else {
temp.add('proxyencrypt/java')
}
java.srcDirs = temp
temp = ['envcheck/libs', 'simulator/libs']
if (BAIHE_SDK) {
temp.add('proxyencryptsms/libs')
} else {
temp.add('proxyencrypt/libs')
}
jniLibs.srcDirs = temp
temp = ['envcheck/res', 'simulator/res']
if (BAIHE_SDK) {
temp.add('proxyencryptsms/res')
} else {
temp.add('proxyencrypt/res')
}
res.srcDirs = temp
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
buildConfigField "boolean", "LOG_MODE", "false"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
buildConfigField "boolean", "LOG_MODE", "true"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
//type: org.gradle.api.tasks.Copy
task copyCacheClass(group: "自定义任务") {
//D:\luozheng\checkAndProtocolFix\mergeincludearr\build\intermediates\classes\release
doFirst {
if (!BAIHE_SDK) {
copy {
from('cacheclass')
into("build/intermediates/classes/release")
}
copy {
from('cacheclass')
into("build/intermediates/classes/debug")
}
print "复制缓存文件\n"
}
}
}
//D:\luozheng\checkAndProtocolFix\mergeincludearr\build\intermediates\intermediate-jars\release
def deleteCache = false;
//dependsOn: build
task 更新当前SDK到生产SDK目录(group: "自定义任务", dependsOn: build) {
def sdkjarlib = "${publishDir}/sdkjar/libs"
def sdkarrlib = "${publishDir}/sdkarr/libs"
doLast {
//清空存档。
print "arrdir ${arrDir} \n"
print "jarDir ${jarDir} \n"
print "jniDir ${jniDir} \n"
if (!new File(sdkarrlib).exists()) {
new File(sdkarrlib).mkdirs();
print "sdk arr 不存在 "
}
if (!new File("${publishDir}/sdkjar/res").exists()) {//eclipse 报错
new File("${publishDir}/sdkjar/res").mkdirs();
print "sdk arr 不存在 "
}
if (!new File(sdkjarlib).exists()) {
print "sdk jar 不存在 "
new File(sdkjarlib).mkdirs();
} else {
print "sdk jar 存在 "
}
//-------------------------------------------
print " sdk arr do \n"
copy {//不根据根目录定位,容易找不到路径
from(arrDir)
into(sdkarrlib)
rename { "peoplesdk.aar" }
}
print "self sdk arr do \n"
copy {
from(arrDir)
into("${project.rootDir}/sdkarr/libs")
rename { "peoplesdk.aar" }
}
//-------------------------------------------
print "demo source do \n"
copy {
from("${project.rootDir}/app/")
into("${publishDir}/app/")
exclude {
details ->
details.file.name.equals("build") || details.file.name.endsWith(".iml") || details.file.name.endsWith(".class")
}
}
//-------------------------------------------
print " sdk jar do \n"
}
print "self sdk jar do \n"
copy {
from(jarDir)
into("${project.rootDir}/sdkjar/libs")
rename { "peoplesdk.jar" }
}
copy {//复制jni
from(jniDir)
into("${project.rootDir}/sdkjar/libs")
}
copy {
from("${project.rootDir}/sdkjar/")
into("${publishDir}/sdkjar/")
exclude {
details ->
details.file.name.equals("build") || details.file.name.endsWith(".iml") || details.file.name.endsWith(".class")
}
}
}
task 打包SDK生成压缩包(type: Zip, group: "自定义任务") {
print "扫描压缩"
def date = new SimpleDateFormat("yyyy-MM-dd-HHmm").format(new Date());
print "执行压缩任务!"
from("${publishDir}")
archiveName "爱加密加密解密与环境检测sdk_${android.defaultConfig.versionName}_${date}.zip"
destinationDir = file("../out/")
exclude {
details ->
details.file.name.equals(".gradle") || details.file.name.equals("bin") || details.file.name.equals(".idea") || details.file.name.equals("gen") || details.file.name.equals("build") || details.file.name.endsWith(".iml") || details.file.name.endsWith(".class") || details.file.name.endsWith(".bak")
}
doFirst {
print "执行压缩任务的doLast执行"
}
}
task 清除生成SDK目录的build文件(group: "自定义任务") {
doFirst {
print "\n删除SDK目录垃圾文件"
delete("${publishDir}/.idea")
delete("${publishDir}/checkAndProtocolPublish.iml")
delete("${publishDir}/.gradle")
delete("${publishDir}/app/build")
delete("${publishDir}/app/bin")
delete("${publishDir}/app/gen")
delete("${publishDir}/app/app.iml")
delete("${publishDir}/.gradle")
delete("${publishDir}/sdkjar/build")
delete("${publishDir}/sdkjar/gen")
delete("${publishDir}/sdkjar/bin")
delete("${publishDir}/sdkarr/build")
delete("${publishDir}/sdklib/sdklib.iml")
delete("${publishDir}/sdkarr/sdklib.iml")
}
}
task 清空文件以便重新拷贝(group: "自定义任务") {
doFirst {
print "\n删除SDK目录垃圾文件"
delete("${project.rootDir}/sdkjar/libs")
delete("${project.rootDir}/sdkjar/res")
delete("${project.rootDir}/sdkjar/src")
delete("${publishDir}/sdkjar/libs")
delete("${publishDir}/sdkjar/res")
delete("${publishDir}/app/src")
delete("${publishDir}/app/res")
}
}
build.dependsOn(copyCacheClass)//通过执行copyFile任务触发 cooyFile在 build之后执行,无法拦截 arr的生成。
dependencies {
compile fileTree(dir: 'envcheck/libs', include: ['*.jar'])
compile fileTree(dir: 'proxyencrypt/libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: ['*.jar'])
}
eclipse开发apk最经常出现的坑就是签名不一致
这种情况只能寻找apk卸载,错误一般是提示看日志,但是压根看不懂日志的。