目前很多公司通过发送一个分享链接来分享软件,分享链接里包含某个分享用户的信息,只要新用户在html中注册这个自己的信息就可以,给分享用户一个福利,如果用我开发的这个jar包,则直接在apk里就能获取谁分享的。减少html页面制作。
需要统计的android项目配置
修改app目录下gradle.build
修改如下配置
buildTypes 中 release 和 debug 配置
buildConfigField “String”, “USER_ID”,”\”\”“
buildTypes {
release {
buildConfigField "String", "USER_ID","\"\""
}
debug {
buildConfigField "String", "USER_ID","\"\""
}
}
gradle.build android 下配置
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
def fileName
if (outputFile != null && outputFile.name.endsWith('.apk')) {
if (variant.buildType.name.equals('release')) {
fileName = "${defaultConfig.applicationId}.${USER_ID}${defaultConfig.versionName}.apk"
} else if (variant.buildType.name.equals('debug')) {
fileName = "${defaultConfig.applicationId}.${USER_ID}${defaultConfig.versionName}.apk"
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
再添加一个常量
ext {
USER_ID= ""
}
整体配置如下
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.ndileber.ndilebertest"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
release {
keyAlias 'key0'
keyPassword '123456'
storeFile file('keystore/dileber.jks')
storePassword '123456'
}
}
buildTypes {
release {
buildConfigField "String", "USER_ID","\"\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
buildConfigField "String", "USER_ID","\"\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
def fileName
if (outputFile != null && outputFile.name.endsWith('.apk')) {
if (variant.buildType.name.equals('release')) {
fileName = "${defaultConfig.applicationId}.${USER_ID}${defaultConfig.versionName}.apk"
} else if (variant.buildType.name.equals('debug')) {
fileName = "${defaultConfig.applicationId}.${USER_ID}${defaultConfig.versionName}.apk"
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
ext {
USER_ID= ""
}
在android代码中获取 userId,可以统计userid的渠道
String userId = BuildConfig.USER_ID;
运行的jar包的配置
config.properties
//android项目盘符
dir=D:
//android项目目录
src=\\workspace\\NdileberTest
//jar包零时文件(随便设置)
temp=F:\\temp\\temp
//gradle目录
GRADLE_SRC=D:\\soft\\Android\\Android Studio\\gradle\\gradle-3.3
运行 6969就是用户userId,导出的包则是包含用户信息,这个jar可以嵌入服务器中使用。线上一键打包
java -jar gradleUser.jar 6969
jar包下载地址
jar包下载地址