Skip to content

Commit ff725dd

Browse files
lixiaoliang04lixiaoliang04
authored andcommitted
调整maven以及修复多线程加载so问题
1 parent bd4ae0a commit ff725dd

File tree

273 files changed

+434
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+434
-411
lines changed

README.md

Lines changed: 4 additions & 4 deletions

app/build.gradle

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ android {
99
compileSdk 33
1010
defaultConfig {
1111
applicationId "com.imf.test"
12-
minSdkVersion 14
13-
//noinspection ExpiredTargetSdkVersion
14-
targetSdkVersion 28
12+
minSdkVersion 21
13+
targetSdkVersion 30
1514
versionCode 1
1615
versionName "1.0"
1716

@@ -30,18 +29,6 @@ android {
3029
}
3130
}
3231

33-
// flavorDimensions "default"
34-
// productFlavors {
35-
// ioTestV7a {
36-
// dimension "default"
37-
// ndk.abiFilters("armeabi-v7a")
38-
// }
39-
// ioTestV8a {
40-
// dimension "default"
41-
// ndk.abiFilters("arm64-v8a")
42-
// }
43-
// }
44-
4532
sourceSets {
4633
main {
4734
jniLibs.srcDirs = ['libs']

app/src/main/java/com/imf/test/MainActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity {
2828

2929
@Override
3030
protected void onCreate(Bundle savedInstanceState) {
31+
checkSoLoad();
3132
fullScreen();
3233
super.onCreate(savedInstanceState);
3334
setContentView(R.layout.activity_main);
@@ -37,7 +38,6 @@ protected void onCreate(Bundle savedInstanceState) {
3738
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.image);
3839
updateCacheDir();
3940
TextView tv = findViewById(R.id.sample_text);
40-
checkSoLoad();
4141
tv.setOnClickListener(v -> {
4242
StringBuilder stringBuilder = new StringBuilder();
4343
v.postDelayed(new Runnable() {
@@ -95,7 +95,7 @@ public void run() {
9595
}
9696

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

101101
public void onClearSoFile(View view) {
@@ -136,19 +136,19 @@ private boolean deleteDir(File dir) {
136136
return dir.delete();
137137
}
138138

139-
private String getDirInfo(File file) {
139+
private String getDirInfo(File file, String startStr) {
140140
if (file.isDirectory()) {
141141
StringBuilder stringBuilder = new StringBuilder();
142142
stringBuilder.append(file.getName()).append("(dir):[\n");
143143
File[] children = file.listFiles();
144144
for (int i = 0; i < children.length; i++) {
145145
File child = children[i];
146-
stringBuilder.append(getDirInfo(child)).append("\n");
146+
stringBuilder.append(getDirInfo(child, startStr + "\t\t")).append("\n");
147147
}
148148
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
149-
return stringBuilder.insert(0, "\t- ").append(" ]").toString();
149+
return stringBuilder.insert(0, startStr + "\t- ").append(" ]").toString();
150150
} else {
151-
return "\t\t* " + file.getName();
151+
return startStr + "\t\t* " + file.getName();
152152
}
153153
}
154154

build.gradle

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
repositories {
4+
maven { url uri("${rootDir}/maven") }
45
mavenLocal()
56
mavenCentral()
67
maven { url "https://jitpack.io" }
7-
maven { url uri("${rootDir}/maven") }
88
maven { url "https://maven.aliyun.com/repository/google" }
99
maven { url "https://maven.aliyun.com/repository/jcenter" }
1010
}
1111
dependencies {
1212
classpath "com.android.tools.build:gradle:$ANDROID_GRADLE_VERSION"
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
1414
if (Boolean.parseBoolean(userPlugin)) {
15-
classpath "com.imf.so:load-hook-plugin:${SO_PLUGIN_VERSION}"
16-
classpath "com.imf.so:file-plugin:${SO_PLUGIN_VERSION}"
15+
classpath "${GROUP_ID}:load-hook-plugin:${SO_PLUGIN_VERSION}"
16+
classpath "${GROUP_ID}:file-plugin:${SO_PLUGIN_VERSION}"
1717
}
1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
@@ -22,10 +22,10 @@ buildscript {
2222

2323
allprojects {
2424
repositories {
25+
maven { url uri("${project.rootProject.rootDir}/maven") }
2526
mavenLocal()
2627
mavenCentral()
2728
maven { url "https://jitpack.io" }
28-
maven { url uri("${project.rootProject.rootDir}/maven") }
2929
maven { url "https://maven.aliyun.com/repository/google" }
3030
maven { url "https://maven.aliyun.com/repository/jcenter" }
3131
maven { url "https://raw.githubusercontent.com/Android-Mainli/Maven/master" }
@@ -89,10 +89,4 @@ subprojects { pro ->
8989
}
9090
}
9191
}
92-
}
93-
94-
task aaa {
95-
doLast {
96-
println org.gradle.internal.os.OperatingSystem.current()
97-
}
9892
}

file-plugin/src/main/kotlin/com/imf/plugin/so/Plugin.kt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,9 @@ abstract class SoFilePlugin : Plugin<Project> {
4747

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

50-
//region 尝试查找 aar 里面的可执行文件
51-
val depAAR = project.dependencies.add(
52-
p7zConfig.name, mapOf(
53-
"group" to "com.github.mcxinyu.Android-So-Handler",
54-
"name" to "p7z",
55-
"classifier" to "all",
56-
"version" to "0.0.9-fix1",
57-
"ext" to "aar"
58-
)
59-
)
60-
runCatching {
61-
val aar = p7zConfig.fileCollection(depAAR).singleFile
62-
ZipFile(aar).unzipTo(aar.parentFile)
63-
val file = aar.parentFile.listFiles()?.firstOrNull {
64-
it.name.contains(osdetector.classifier)
65-
} ?: throw FileNotFoundException()
66-
if (!file.canExecute() && !file.setExecutable(true)) {
67-
throw GradleException("Cannot set ${file} as executable")
68-
}
69-
return file.absolutePath
70-
}
71-
//endregion
72-
7350
val dep = project.dependencies.add(
7451
p7zConfig.name, mapOf<String, String>(
75-
"group" to "com.mainli",
52+
"group" to "com.github.mainlxl.Android-So-Handler",
7653
"name" to "p7z",
7754
"classifier" to osdetector.classifier,
7855
"version" to "1.0.1",
@@ -86,6 +63,7 @@ abstract class SoFilePlugin : Plugin<Project> {
8663
}
8764
return file.absolutePath
8865
}
66+
// 兜底使用系统环境变量配置的7z命令
8967
val os = System.getenv("OS")?.lowercase()
9068
if (os != null && os.contains("windows")) {
9169
return "7z.exe"

gradle.properties

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020
ANDROID_GRADLE_VERSION=7.3.0
2121
#SO_PLUGIN_VERSION=0.0.4-SNAPSHOT
22-
#SO_PLUGIN_VERSION=0.0.9
23-
SO_PLUGIN_VERSION=0.0.9-fix-local
22+
SO_PLUGIN_VERSION=0.0.11
2423
userPlugin=true
25-
26-
GROUP_ID=com.imf.so
24+
GROUP_ID=com.github.mainlxl.Android-So-Handler

load-hook/src/main/java/com/imf/so/SoLoadHook.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
* @Description: so库加载代理
77
*/
88
public class SoLoadHook {
9-
public static SoLoadProxy DEFAULT_SYSTEM_LOAD = new DefaultSoLoadProxy();
10-
private static SoLoadProxy sSoLoadProxy = DEFAULT_SYSTEM_LOAD;
9+
private static volatile SoLoadProxy sSoLoadProxy = new DefaultSoLoadProxy();
1110

1211
public static void setSoLoadProxy(SoLoadProxy soLoadProxy) {
1312
if (soLoadProxy == null) {
14-
sSoLoadProxy = DEFAULT_SYSTEM_LOAD;
1513
return;
1614
}
1715
sSoLoadProxy = soLoadProxy;
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
df7c8738d80b3e040f331dff3c1a573b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
612410c467d653fce6f71e262763088f1c9ec72f

0 commit comments

Comments
 (0)