mirror of
https://github.com/HighCapable/YukiReflection.git
synced 2025-09-05 10:15:40 +08:00
Modify merge yukireflection java-library project to android-library project
This commit is contained in:
@@ -1,31 +1,33 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'org.jetbrains.kotlin.jvm'
|
||||
id 'com.android.library'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
sourceSets.main { java.srcDir("src/api/kotlin") }
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
android {
|
||||
namespace 'com.highcapable.yukireflection'
|
||||
compileSdk 33
|
||||
|
||||
javadoc {
|
||||
options.addStringOption("charset", "UTF-8")
|
||||
if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption('html5', true)
|
||||
}
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
|
||||
kotlin {
|
||||
sourceSets.main { kotlin.srcDir("src/api/kotlin") }
|
||||
sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } }
|
||||
}
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = 11
|
||||
jvmTarget = '11'
|
||||
freeCompilerArgs = [
|
||||
'-opt-in=com.highcapable.yukireflection.annotation.YukiPrivateApi',
|
||||
'-Xno-param-assertions',
|
||||
@@ -33,11 +35,27 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
||||
'-Xno-receiver-assertions'
|
||||
]
|
||||
}
|
||||
lintOptions {
|
||||
checkReleaseBuilds false
|
||||
}
|
||||
publishing {
|
||||
singleVariant('release') {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin { sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } } }
|
||||
|
||||
dependencies {
|
||||
compileOnly fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.annotation:annotation:1.6.0'
|
||||
implementation 'androidx.core:core-ktx:1.10.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
|
||||
@@ -45,9 +63,10 @@ version = rootProject.ext.apiVersion
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
release(MavenPublication) {
|
||||
artifactId = 'api'
|
||||
from components.java
|
||||
artifact "$buildDir/outputs/aar/${project.name}-release.aar"
|
||||
artifact androidSourcesJar
|
||||
pom {
|
||||
name = rootProject.ext.repoName
|
||||
description = rootProject.ext.repoDescription
|
||||
@@ -86,6 +105,4 @@ publishing {
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
sign(publishing.publications.mavenJava)
|
||||
}
|
||||
signing { sign publishing.publications }
|
0
yukireflection/consumer-rules.pro
Normal file
0
yukireflection/consumer-rules.pro
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21
yukireflection/proguard-rules.pro
vendored
Normal file
21
yukireflection/proguard-rules.pro
vendored
Normal 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
|
2
yukireflection/src/main/AndroidManifest.xml
Normal file
2
yukireflection/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest />
|
@@ -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.type.factory.ModifierConditions
|
||||
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.runBlocking
|
||||
import com.highcapable.yukireflection.utils.toStackTrace
|
||||
import dalvik.system.BaseDexClassLoader
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Field
|
||||
@@ -84,13 +86,15 @@ class DexClassFinder @PublishedApi internal constructor(
|
||||
* 通过 [Context] 获取当前 [SharedPreferences]
|
||||
* @param versionName 版本名称 - 默认空
|
||||
* @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)
|
||||
?.let { "${CACHE_FILE_NAME}_${versionName ?: it.versionName}_${versionCode ?: PackageInfoCompat.getLongVersionCode(it)}" }
|
||||
?: "${CACHE_FILE_NAME}_unknown",
|
||||
Context.MODE_PRIVATE)
|
||||
}.onFailure { yLoggerW(msg = "Failed to read app's SharedPreferences when using DexClassFinder\n${it.toStackTrace()}") }.getOrNull()
|
||||
|
||||
/**
|
||||
* 清除当前 [DexClassFinder] 的 [Class] 缓存
|
||||
@@ -101,7 +105,7 @@ class DexClassFinder @PublishedApi internal constructor(
|
||||
* @param versionCode 版本号 - 默认空
|
||||
*/
|
||||
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
|
||||
@@ -451,7 +455,7 @@ class DexClassFinder @PublishedApi internal constructor(
|
||||
takeIf { it.isNotEmpty() }?.forEach { names.add(it.name) }
|
||||
context?.also {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
@@ -33,6 +33,7 @@ package com.highcapable.yukireflection.type.java
|
||||
import android.os.Build
|
||||
import com.highcapable.yukireflection.factory.classOf
|
||||
import com.highcapable.yukireflection.factory.toClass
|
||||
import com.highcapable.yukireflection.factory.toClassOrNull
|
||||
import dalvik.system.BaseDexClassLoader
|
||||
import dalvik.system.DexClassLoader
|
||||
import dalvik.system.InMemoryDexClassLoader
|
||||
@@ -48,7 +49,6 @@ import java.lang.reflect.Member
|
||||
import java.lang.reflect.Method
|
||||
import java.net.HttpCookie
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.http.HttpClient
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
@@ -633,9 +633,9 @@ val HttpCookieClass get() = classOf<HttpCookie>()
|
||||
|
||||
/**
|
||||
* 获得 [HttpClient] 类型
|
||||
* @return [Class]<[HttpClient]>
|
||||
* @return [Class] or null
|
||||
*/
|
||||
val HttpClientClass get() = classOf<HttpClient>()
|
||||
val HttpClientClass get() = "java.net.http.HttpClient".toClassOrNull()
|
||||
|
||||
/**
|
||||
* 获得 [AtomicBoolean] 类型
|
Reference in New Issue
Block a user