Skip to content

Commit

Permalink
add maven
Browse files Browse the repository at this point in the history
  • Loading branch information
lwj1994 committed May 29, 2023
1 parent d1b0b83 commit 07f3a9c
Show file tree
Hide file tree
Showing 318 changed files with 312 additions and 164 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## android_privacy_hook

基于 Booster 对隐私 api 进行 hook,用户同意之前返回空值。同意之后才调用原有的 api。



## 使用

root build.gradle:
```gradle
buildscript {
ext.booster_version = '4.16.2'
ext.privacyhook_version = '0.0.1'
repositories {
google()
mavenCentral()
}
dependencies {
// 依赖 booster
classpath "com.didiglobal.booster:booster-gradle-plugin:$booster_version"
// privacyhook:transform
classpath "com.lwjlol.privacyhook:transform:$privacyhook_version"
}
}
```

app 的 build.gradle
```gradle
dependencies {
implementation 'com.lwjlol.privacyhook:core:0.0.1'
}
```
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.didiglobal.booster'
}

android {
Expand All @@ -24,19 +25,19 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '11'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation project(":privacy_hook")
implementation project(':core')
implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Binary file removed app/libs/transform.jar
Binary file not shown.
17 changes: 15 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Android_privacy_hook" />
android:theme="@style/Theme.Android_privacy_hook" >
<activity
android:name=".Main"
android:exported="true"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</manifest>
</activity>

</application>

</manifest>
39 changes: 39 additions & 0 deletions app/src/main/java/com/lwjlol/privacyhook/demo/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.lwjlol.privacyhook.demo

import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.lwjlol.privacyhook.PrivacyHooker

/**
* @author luwenjie on 2023/5/29 13:51:41
*/
class Main : AppCompatActivity() {
private var agree = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PrivacyHooker.isUserAgreed = {
agree
}
val dialog = AlertDialog.Builder(this)
.setPositiveButton(
"同意",
DialogInterface.OnClickListener { dialog, which ->
agree = true
},
)
.setNegativeButton(
"不同意",
DialogInterface.OnClickListener { dialog, which ->
agree = false
},
)
.setMessage("是否同意隐私协议?")
dialog.show()
}

companion object {
private const val TAG = "Main"
}
}
29 changes: 26 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath files("transform.jar")
classpath "com.didiglobal.booster:booster-task-analyser:4.16.2"
}
}
plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
}
id 'com.didiglobal.booster' version '4.16.2' apply false
}

// load local.properties
Properties properties = new Properties()
if (project.file('local.properties').exists()) {
properties.load(project.file('local.properties').newDataInputStream())
properties.entrySet().each {
project.ext.set(it.key, it.value)
}
}


File renamed without changes.
8 changes: 5 additions & 3 deletions privacy_hook/build.gradle → core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'org.jetbrains.kotlin.android'
}

apply from: "${rootProject.projectDir}/plugin_maven_publish_aar.gradle"

android {
namespace 'com.lwjlol.privacyhook'
compileSdk 33
Expand All @@ -22,11 +24,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '11'
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 17 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true



LIB_GROUP=com.lwjlol.privacyhook
LIB_VERSION=0.0.1
LIB_DES=An Android library based on Kotlin Coroutines and DAG(Directd Acyclic Graph), which schdules dependent tasks.
LIB_URL=https://github.com/lwj1994/privacy_hook

SCM_URL=[email protected]:lwj1994/privacy_hook.git

DEVELOPER_NAME=wen
DEVELOPER_EMAIL=[email protected]

LICENSE_NAME=The Apache Software License, Version 2.0
LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
LICENSE_DIST=repo
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 29 11:44:52 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
82 changes: 82 additions & 0 deletions plugin_maven_publish_aar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

// 设置group和版本名称
group = LIB_GROUP
version = LIB_VERSION

// 如何配置,参考文档:https://developer.android.com/studio/publish-library
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}

def LIB_ARTIFACT = project.name
println("LIB_ARTIFACT = $LIB_ARTIFACT")

publishing {
publications {
// release:自定义发布产物名称
release(MavenPublication) {
artifactId LIB_ARTIFACT
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact androidSourcesJar

pom {
name = LIB_ARTIFACT
description = LIB_DES
url = LIB_URL
licenses {
license {
name = LICENSE_NAME
url = LICENSE_URL
distribution = LICENSE_DIST
}
}
developers {
developer {
name = DEVELOPER_NAME
email = DEVELOPER_EMAIL
}
}
scm {
url = SCM_URL
connection = 'scm:git:github.com/lwj1994/privacy_hook.git'
developerConnection = 'scm:git:ssh://github.com/lwj1994/privacy_hook.git'
}
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
repositories {
maven {
// change URLs to point to your repos, e.g. http://my.org/repo
def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
def mavenUrl = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
url = mavenUrl

println("publish to mavenUrl=$mavenUrl")
// 校验不支持本地文件目录
if (mavenUrl.startsWith("https")) {
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
}

signing {
sign publishing.publications.release
}
79 changes: 79 additions & 0 deletions plugin_maven_publish_jar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

// 设置group和版本名称
group = LIB_GROUP
version = LIB_VERSION

// 如何配置,参考文档:https://developer.android.com/studio/publish-library
java {
withJavadocJar()
withSourcesJar()
}
def LIB_ARTIFACT = project.name
println("LIB_ARTIFACT = $LIB_ARTIFACT")

publishing {
publications {
// release:自定义发布产物名称
release(MavenPublication) {
afterEvaluate {
from components.java
}
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}

artifactId = LIB_ARTIFACT

pom {
name = LIB_ARTIFACT
description = LIB_DES
url = LIB_URL
licenses {
license {
name = LICENSE_NAME
url = LICENSE_URL
distribution = LICENSE_DIST
}
}
developers {
developer {
name = DEVELOPER_NAME
email = DEVELOPER_EMAIL
}
}
scm {
url = SCM_URL
}
}
}
}
repositories {
maven {
// change URLs to point to your repos, e.g. http://my.org/repo
def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
def mavenUrl = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
url = mavenUrl

println("publish to mavenUrl=$mavenUrl")
// 校验不支持本地文件目录
if (mavenUrl.startsWith("https")) {
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
}

signing {
sign publishing.publications.release
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dependencyResolutionManagement {
}
rootProject.name = "android_privacy_hook"
include ':app'
include ':privacy_hook'
include ':core'
include ':transform'
Binary file added transform.jar
Binary file not shown.
Loading

0 comments on commit 07f3a9c

Please sign in to comment.