Modify merge yukireflection java-library project to android-library project

This commit is contained in:
2023-04-15 21:19:05 +08:00
parent 082fa898df
commit bb2bfb0dda
58 changed files with 77 additions and 33 deletions

View File

@@ -1,31 +1,33 @@
plugins { plugins {
id 'java-library' id 'com.android.library'
id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.kotlin.android'
id 'maven-publish' id 'maven-publish'
id 'signing' id 'signing'
} }
java { android {
sourceCompatibility = JavaVersion.VERSION_11 namespace 'com.highcapable.yukireflection'
targetCompatibility = JavaVersion.VERSION_11 compileSdk 33
sourceSets.main { java.srcDir("src/api/kotlin") }
withJavadocJar() defaultConfig {
withSourcesJar() minSdk 21
targetSdk 33
consumerProguardFiles 'consumer-rules.pro'
} }
javadoc { buildTypes {
options.addStringOption("charset", "UTF-8") release {
if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption('html5', true) minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
kotlin {
sourceSets.main { kotlin.srcDir("src/api/kotlin") }
sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } }
} }
compileOptions {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions { kotlinOptions {
jvmTarget = 11 jvmTarget = '11'
freeCompilerArgs = [ freeCompilerArgs = [
'-opt-in=com.highcapable.yukireflection.annotation.YukiPrivateApi', '-opt-in=com.highcapable.yukireflection.annotation.YukiPrivateApi',
'-Xno-param-assertions', '-Xno-param-assertions',
@@ -33,11 +35,27 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
'-Xno-receiver-assertions' '-Xno-receiver-assertions'
] ]
} }
lintOptions {
checkReleaseBuilds false
}
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
} }
kotlin { sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } } }
dependencies { dependencies {
compileOnly fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.annotation:annotation:1.6.0' implementation 'androidx.appcompat:appcompat:1.6.1'
}
tasks.register('androidSourcesJar', Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
} }
group = rootProject.ext.groupId group = rootProject.ext.groupId
@@ -45,9 +63,10 @@ version = rootProject.ext.apiVersion
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { release(MavenPublication) {
artifactId = 'api' artifactId = 'api'
from components.java artifact "$buildDir/outputs/aar/${project.name}-release.aar"
artifact androidSourcesJar
pom { pom {
name = rootProject.ext.repoName name = rootProject.ext.repoName
description = rootProject.ext.repoDescription description = rootProject.ext.repoDescription
@@ -86,6 +105,4 @@ publishing {
} }
} }
signing { signing { sign publishing.publications }
sign(publishing.publications.mavenJava)
}

View File

Binary file not shown.

21
yukireflection/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />

View File

@@ -49,8 +49,10 @@ import com.highcapable.yukireflection.finder.classes.rules.result.MemberRulesRes
import com.highcapable.yukireflection.finder.tools.ReflectionTool import com.highcapable.yukireflection.finder.tools.ReflectionTool
import com.highcapable.yukireflection.finder.type.factory.ModifierConditions import com.highcapable.yukireflection.finder.type.factory.ModifierConditions
import com.highcapable.yukireflection.finder.type.factory.NameConditions import com.highcapable.yukireflection.finder.type.factory.NameConditions
import com.highcapable.yukireflection.log.yLoggerW
import com.highcapable.yukireflection.utils.await import com.highcapable.yukireflection.utils.await
import com.highcapable.yukireflection.utils.runBlocking import com.highcapable.yukireflection.utils.runBlocking
import com.highcapable.yukireflection.utils.toStackTrace
import dalvik.system.BaseDexClassLoader import dalvik.system.BaseDexClassLoader
import java.lang.reflect.Constructor import java.lang.reflect.Constructor
import java.lang.reflect.Field import java.lang.reflect.Field
@@ -84,13 +86,15 @@ class DexClassFinder @PublishedApi internal constructor(
* 通过 [Context] 获取当前 [SharedPreferences] * 通过 [Context] 获取当前 [SharedPreferences]
* @param versionName 版本名称 - 默认空 * @param versionName 版本名称 - 默认空
* @param versionCode 版本号 - 默认空 * @param versionCode 版本号 - 默认空
* @return [SharedPreferences] * @return [SharedPreferences] or null
*/ */
private fun Context.currentSp(versionName: String? = null, versionCode: Long? = null) = private fun Context.currentSp(versionName: String? = null, versionCode: Long? = null) = runCatching {
@Suppress("DEPRECATION")
getSharedPreferences(packageManager?.getPackageInfo(packageName, PackageManager.GET_META_DATA) getSharedPreferences(packageManager?.getPackageInfo(packageName, PackageManager.GET_META_DATA)
?.let { "${CACHE_FILE_NAME}_${versionName ?: it.versionName}_${versionCode ?: PackageInfoCompat.getLongVersionCode(it)}" } ?.let { "${CACHE_FILE_NAME}_${versionName ?: it.versionName}_${versionCode ?: PackageInfoCompat.getLongVersionCode(it)}" }
?: "${CACHE_FILE_NAME}_unknown", ?: "${CACHE_FILE_NAME}_unknown",
Context.MODE_PRIVATE) Context.MODE_PRIVATE)
}.onFailure { yLoggerW(msg = "Failed to read app's SharedPreferences when using DexClassFinder\n${it.toStackTrace()}") }.getOrNull()
/** /**
* 清除当前 [DexClassFinder] [Class] 缓存 * 清除当前 [DexClassFinder] [Class] 缓存
@@ -101,7 +105,7 @@ class DexClassFinder @PublishedApi internal constructor(
* @param versionCode 版本号 - 默认空 * @param versionCode 版本号 - 默认空
*/ */
fun clearCache(context: Context, versionName: String? = null, versionCode: Long? = null) = fun clearCache(context: Context, versionName: String? = null, versionCode: Long? = null) =
context.currentSp(versionName, versionCode).edit().clear().apply() context.currentSp(versionName, versionCode)?.edit()?.clear()?.apply() ?: yLoggerW(msg = "Failed to clear DexClassFinder's cache")
} }
@PublishedApi @PublishedApi
@@ -451,7 +455,7 @@ class DexClassFinder @PublishedApi internal constructor(
takeIf { it.isNotEmpty() }?.forEach { names.add(it.name) } takeIf { it.isNotEmpty() }?.forEach { names.add(it.name) }
context?.also { context?.also {
if (it.packageName == "android") error("Cannot create classes cache for \"android\", please remove \"name\" param") if (it.packageName == "android") error("Cannot create classes cache for \"android\", please remove \"name\" param")
it.currentSp().edit().apply { putStringSet(name, names) }.apply() it.currentSp()?.edit()?.apply { putStringSet(name, names) }?.apply() ?: yLoggerW(msg = "Failed to use caching in DexClassFinder")
} }
} }
} }

View File

@@ -33,6 +33,7 @@ package com.highcapable.yukireflection.type.java
import android.os.Build import android.os.Build
import com.highcapable.yukireflection.factory.classOf import com.highcapable.yukireflection.factory.classOf
import com.highcapable.yukireflection.factory.toClass import com.highcapable.yukireflection.factory.toClass
import com.highcapable.yukireflection.factory.toClassOrNull
import dalvik.system.BaseDexClassLoader import dalvik.system.BaseDexClassLoader
import dalvik.system.DexClassLoader import dalvik.system.DexClassLoader
import dalvik.system.InMemoryDexClassLoader import dalvik.system.InMemoryDexClassLoader
@@ -48,7 +49,6 @@ import java.lang.reflect.Member
import java.lang.reflect.Method import java.lang.reflect.Method
import java.net.HttpCookie import java.net.HttpCookie
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.http.HttpClient
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
@@ -633,9 +633,9 @@ val HttpCookieClass get() = classOf<HttpCookie>()
/** /**
* 获得 [HttpClient] 类型 * 获得 [HttpClient] 类型
* @return [Class]<[HttpClient]> * @return [Class] or null
*/ */
val HttpClientClass get() = classOf<HttpClient>() val HttpClientClass get() = "java.net.http.HttpClient".toClassOrNull()
/** /**
* 获得 [AtomicBoolean] 类型 * 获得 [AtomicBoolean] 类型