Skip to content

Commit

Permalink
调整maven以及修复多线程加载so问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiaoliang04 authored and lixiaoliang04 committed Sep 21, 2023
1 parent bd4ae0a commit ff725dd
Show file tree
Hide file tree
Showing 273 changed files with 434 additions and 411 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ buildscript {
dependencies {
// ...
if (userSoPlugin) {
classpath("com.github.Android-Mainli:Android-So-Handler:load-hook-plugin:${Versions.so_plugin_version}")
classpath("com.github.Android-Mainli:Android-So-Handler:file-plugin:${Versions.so_plugin_version}")
classpath("com.github.mainlxl.Android-So-Handler:load-hook-plugin:${Versions.so_plugin_version}")
classpath("com.github.mainlxl.Android-So-Handler:file-plugin:${Versions.so_plugin_version}")
}
}
}
Expand All @@ -26,8 +26,8 @@ repositories {
maven("https://jitpack.io")
}
dependencies {
implementation "com.github.Android-Mainli:Android-So-Handler:load-hook:${Versions.so_plugin_version}"
implementation "com.github.Android-Mainli:Android-So-Handler:load-assets-7z:${Versions.so_plugin_version}"
implementation "com.github.mainlxl.Android-So-Handler:load-hook:${Versions.so_plugin_version}"
implementation "com.github.mainlxl.Android-So-Handler:load-assets-7z:${Versions.so_plugin_version}"
}
```

Expand Down
17 changes: 2 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ android {
compileSdk 33
defaultConfig {
applicationId "com.imf.test"
minSdkVersion 14
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 28
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand All @@ -30,18 +29,6 @@ android {
}
}

// flavorDimensions "default"
// productFlavors {
// ioTestV7a {
// dimension "default"
// ndk.abiFilters("armeabi-v7a")
// }
// ioTestV8a {
// dimension "default"
// ndk.abiFilters("arm64-v8a")
// }
// }

sourceSets {
main {
jniLibs.srcDirs = ['libs']
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/imf/test/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
checkSoLoad();
fullScreen();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Expand All @@ -37,7 +38,6 @@ protected void onCreate(Bundle savedInstanceState) {
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.image);
updateCacheDir();
TextView tv = findViewById(R.id.sample_text);
checkSoLoad();
tv.setOnClickListener(v -> {
StringBuilder stringBuilder = new StringBuilder();
v.postDelayed(new Runnable() {
Expand Down Expand Up @@ -95,7 +95,7 @@ public void run() {
}

private void updateCacheDir() {
mCache.setText(new StringBuilder().append("缓存目录情况:\n").append(getDirInfo(getJniLibs())));
mCache.setText(new StringBuilder().append("缓存目录情况:\n").append(getDirInfo(getJniLibs(), "")));
}

public void onClearSoFile(View view) {
Expand Down Expand Up @@ -136,19 +136,19 @@ private boolean deleteDir(File dir) {
return dir.delete();
}

private String getDirInfo(File file) {
private String getDirInfo(File file, String startStr) {
if (file.isDirectory()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(file.getName()).append("(dir):[\n");
File[] children = file.listFiles();
for (int i = 0; i < children.length; i++) {
File child = children[i];
stringBuilder.append(getDirInfo(child)).append("\n");
stringBuilder.append(getDirInfo(child, startStr + "\t\t")).append("\n");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
return stringBuilder.insert(0, "\t- ").append(" ]").toString();
return stringBuilder.insert(0, startStr + "\t- ").append(" ]").toString();
} else {
return "\t\t* " + file.getName();
return startStr + "\t\t* " + file.getName();
}
}

Expand Down
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url uri("${rootDir}/maven") }
mavenLocal()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url uri("${rootDir}/maven") }
maven { url "https://maven.aliyun.com/repository/google" }
maven { url "https://maven.aliyun.com/repository/jcenter" }
}
dependencies {
classpath "com.android.tools.build:gradle:$ANDROID_GRADLE_VERSION"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
if (Boolean.parseBoolean(userPlugin)) {
classpath "com.imf.so:load-hook-plugin:${SO_PLUGIN_VERSION}"
classpath "com.imf.so:file-plugin:${SO_PLUGIN_VERSION}"
classpath "${GROUP_ID}:load-hook-plugin:${SO_PLUGIN_VERSION}"
classpath "${GROUP_ID}:file-plugin:${SO_PLUGIN_VERSION}"
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -22,10 +22,10 @@ buildscript {

allprojects {
repositories {
maven { url uri("${project.rootProject.rootDir}/maven") }
mavenLocal()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url uri("${project.rootProject.rootDir}/maven") }
maven { url "https://maven.aliyun.com/repository/google" }
maven { url "https://maven.aliyun.com/repository/jcenter" }
maven { url "https://raw.githubusercontent.com/Android-Mainli/Maven/master" }
Expand Down Expand Up @@ -89,10 +89,4 @@ subprojects { pro ->
}
}
}
}

task aaa {
doLast {
println org.gradle.internal.os.OperatingSystem.current()
}
}
26 changes: 2 additions & 24 deletions file-plugin/src/main/kotlin/com/imf/plugin/so/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,9 @@ abstract class SoFilePlugin : Plugin<Project> {

val osdetector = project.extensions.getByType(OsDetector::class.java)

//region 尝试查找 aar 里面的可执行文件
val depAAR = project.dependencies.add(
p7zConfig.name, mapOf(
"group" to "com.github.mcxinyu.Android-So-Handler",
"name" to "p7z",
"classifier" to "all",
"version" to "0.0.9-fix1",
"ext" to "aar"
)
)
runCatching {
val aar = p7zConfig.fileCollection(depAAR).singleFile
ZipFile(aar).unzipTo(aar.parentFile)
val file = aar.parentFile.listFiles()?.firstOrNull {
it.name.contains(osdetector.classifier)
} ?: throw FileNotFoundException()
if (!file.canExecute() && !file.setExecutable(true)) {
throw GradleException("Cannot set ${file} as executable")
}
return file.absolutePath
}
//endregion

val dep = project.dependencies.add(
p7zConfig.name, mapOf<String, String>(
"group" to "com.mainli",
"group" to "com.github.mainlxl.Android-So-Handler",
"name" to "p7z",
"classifier" to osdetector.classifier,
"version" to "1.0.1",
Expand All @@ -86,6 +63,7 @@ abstract class SoFilePlugin : Plugin<Project> {
}
return file.absolutePath
}
// 兜底使用系统环境变量配置的7z命令
val os = System.getenv("OS")?.lowercase()
if (os != null && os.contains("windows")) {
return "7z.exe"
Expand Down
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ android.useAndroidX=true
android.enableJetifier=true
ANDROID_GRADLE_VERSION=7.3.0
#SO_PLUGIN_VERSION=0.0.4-SNAPSHOT
#SO_PLUGIN_VERSION=0.0.9
SO_PLUGIN_VERSION=0.0.9-fix-local
SO_PLUGIN_VERSION=0.0.11
userPlugin=true

GROUP_ID=com.imf.so
GROUP_ID=com.github.mainlxl.Android-So-Handler
4 changes: 1 addition & 3 deletions load-hook/src/main/java/com/imf/so/SoLoadHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
* @Description: so库加载代理
*/
public class SoLoadHook {
public static SoLoadProxy DEFAULT_SYSTEM_LOAD = new DefaultSoLoadProxy();
private static SoLoadProxy sSoLoadProxy = DEFAULT_SYSTEM_LOAD;
private static volatile SoLoadProxy sSoLoadProxy = new DefaultSoLoadProxy();

public static void setSoLoadProxy(SoLoadProxy soLoadProxy) {
if (soLoadProxy == null) {
sSoLoadProxy = DEFAULT_SYSTEM_LOAD;
return;
}
sSoLoadProxy = soLoadProxy;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
df7c8738d80b3e040f331dff3c1a573b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
612410c467d653fce6f71e262763088f1c9ec72f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d0b3f3de5af3a18adbf1892a4cd376d40a52c1002633615cb14b60b8856bec87
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0d8098ea98a676ccac3c40ca5e248a176e5642c5b98da63aa4c90cdee7d0ceb59cb31b17026ba3fea4e544442b5b6e6286108c6d052885008248270023b1f556
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"formatVersion": "1.1",
"component": {
"group": "com.imf.so",
"group": "com.github.mainlxl.Android-So-Handler",
"module": "android-un7z",
"version": "0.0.9",
"version": "0.0.11",
"attributes": {
"org.gradle.status": "release"
}
Expand All @@ -24,8 +24,8 @@
},
"files": [
{
"name": "android-un7z-0.0.9.aar",
"url": "android-un7z-0.0.9.aar",
"name": "android-un7z-0.0.11.aar",
"url": "android-un7z-0.0.11.aar",
"size": 161771,
"sha512": "1288ca3b5fc8f362b3b4c14751cd1f3154edde97cc31597ef44c3f5b04c3ec6c5b9a5aa9c5246c2a530b8cf1c2e9f7a9f347bb134e90ce0b6142085a904342d2",
"sha256": "1c3ed5f612f47b61a6d27181295f5df8f2b937b790376d834b6f4a2fe0a03a16",
Expand All @@ -44,8 +44,8 @@
},
"files": [
{
"name": "android-un7z-0.0.9.aar",
"url": "android-un7z-0.0.9.aar",
"name": "android-un7z-0.0.11.aar",
"url": "android-un7z-0.0.11.aar",
"size": 161771,
"sha512": "1288ca3b5fc8f362b3b4c14751cd1f3154edde97cc31597ef44c3f5b04c3ec6c5b9a5aa9c5246c2a530b8cf1c2e9f7a9f347bb134e90ce0b6142085a904342d2",
"sha256": "1c3ed5f612f47b61a6d27181295f5df8f2b937b790376d834b6f4a2fe0a03a16",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
036255353ba56cfcd593a7fc52d6e201
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2bc95da807e1d9313cfbba9a74462033f7b6661d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fad4d9e9281b26f1c558afd9e946b15cff811ddaa221ab62b57caebaf312152a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5e2cd67a1e5ed1555f3ebcbbd0087a6b7ae150a4fa1c59d9bb4cda2edca271fbd36d4f2ed449cbf5a0fdb4c1da65acb573ca7d9e7657f7170482d9988d8563f
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.imf.so</groupId>
<groupId>com.github.mainlxl.Android-So-Handler</groupId>
<artifactId>android-un7z</artifactId>
<version>0.0.9</version>
<version>0.0.11</version>
<packaging>aar</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dfc69420e23b400e767395c7df57967a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
349ac0c612a1c15cde75d2729b95559abad8519f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b5d432f2edf2d55780a226e06ad38ec376aa68f02be185e5f727b4f8564d1709
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8bb8d052db09182409e58e66bfd422033adb39ae576f60fd12f78eb0297b13887971ae5a60ef2b99bf28c5e83243fd1525bf57a3177e723e948e674c8e6bf502
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.github.mainlxl.Android-So-Handler</groupId>
<artifactId>android-un7z</artifactId>
<versioning>
<latest>0.0.11</latest>
<release>0.0.11</release>
<versions>
<version>0.0.11</version>
</versions>
<lastUpdated>20230921080404</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
93db3a98d7e74d810f5405bab734b3a9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2d3a4020d95dc464f5c2698a91f2fd04c69e412
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
83d962ec8dcccdca02d942b027674b12467364b2f6d4e8e92283b21f6a15cdbd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1e2f612c9516691f121c63a092ecbfa99157fb51b4e5a8555c49a5c96dd7514b649f1b2fea6262062090016d6a80ac44939eeac1d9a37797817faaab39e2ea24
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cf51f19eebdf52420f777966458a9ec5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4b7907c7fd74579a72846f79ba74caa522b5857e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c591ae9654b4bce5df0a6939c90197008d1674d86614d0f873e8bf3dc8a3802b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
51a5ac4e459a10b89e3592a30bdad008ca6a781cf419b4d58c61fc30789ade5dba5571d1ad73580cff0e7d0d4967c957fea30d68ab042ac4a36b7a9e91251a30
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42ce9f59a2043016fa036f158763a14c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
72317a699184ea813aa0b2e7ed322513b519af26
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8a523ce3fc746283a193197407dccc8aab54be4b558546d2be151d74c3d16a3e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
961789adaa1dd7f2c95ad288d208880dcab995edac477103df26fcef2b6031ef0ade7a27c9518f7b79f7ea7934f50091c1992d6865034630d9c0de26c3f14214
Loading

0 comments on commit ff725dd

Please sign in to comment.