diff --git a/README.md b/README.md index 69417cb..54c080c 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ externalNativeBuild { } } ``` +and specify ndk.dir in local.properties +``` +ndk.dir=your/ndk/path/android-ndk-r17c +``` #### IOS ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index 322127d..6018d04 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -71,6 +71,10 @@ externalNativeBuild { } } ``` +同时在 local.properties 指定ndk.dir +``` +ndk.dir=your/ndk/path/android-ndk-r17c +``` #### IOS ``` diff --git a/demo/whale_android/.gitignore b/demo/whale_android/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/demo/whale_android/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/demo/whale_android/app/.gitignore b/demo/whale_android/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/demo/whale_android/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/demo/whale_android/app/build.gradle b/demo/whale_android/app/build.gradle new file mode 100644 index 0000000..dd5079d --- /dev/null +++ b/demo/whale_android/app/build.gradle @@ -0,0 +1,59 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.lody.whale_android" + minSdkVersion 18 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + externalNativeBuild { + ndkBuild{ + abiFilters "armeabi-v7a" + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + externalNativeBuild { + cmake { + path "../../../CMakeLists.txt" + } + } + + sourceSets{ + main{ + java { + srcDirs "../../../java" + + sourceSets.all{set -> + println "${set.name}的文件是 ${set.java.srcDirs}" + } + } + + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +} diff --git a/demo/whale_android/app/proguard-rules.pro b/demo/whale_android/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/demo/whale_android/app/proguard-rules.pro @@ -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 diff --git a/demo/whale_android/app/src/androidTest/java/com/easoll/whale_android/ExampleInstrumentedTest.kt b/demo/whale_android/app/src/androidTest/java/com/easoll/whale_android/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..b368edf --- /dev/null +++ b/demo/whale_android/app/src/androidTest/java/com/easoll/whale_android/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.easoll.whale_android + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.easoll.whale_android", appContext.packageName) + } +} diff --git a/demo/whale_android/app/src/main/AndroidManifest.xml b/demo/whale_android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6f8f999 --- /dev/null +++ b/demo/whale_android/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/whale_android/app/src/main/java/com/lody/whale/demo/MainActivity.kt b/demo/whale_android/app/src/main/java/com/lody/whale/demo/MainActivity.kt new file mode 100644 index 0000000..dc5ee23 --- /dev/null +++ b/demo/whale_android/app/src/main/java/com/lody/whale/demo/MainActivity.kt @@ -0,0 +1,51 @@ +package com.lody.whale.demo + +import android.annotation.SuppressLint +import android.os.Bundle +import android.util.Log +import android.view.View +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import com.lody.whale.xposed.XC_MethodHook +import com.lody.whale.xposed.XposedBridge +import com.lody.whale_android.R +import java.lang.RuntimeException + +/** + * @Author: xiongyiming + * @Time: 2019-09-03 21:34 + * @Description: + */ +class MainActivity: AppCompatActivity(){ + companion object{ + private const val TAG = "MainActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_main) + + hookMethod() + + findViewById(R.id.btn_test).setOnClickListener { + Toast.makeText(this, "hello", Toast.LENGTH_SHORT).show() + } + + } + + private fun hookMethod(){ + val method = Toast::class.java.getDeclaredMethod("show") + + XposedBridge.hookMethod(method, object : XC_MethodHook(){ + @SuppressLint("ShowToast") + override fun beforeHookedMethod(param: MethodHookParam) { + val e = RuntimeException() + Log.e(TAG, "replaceHookedMethod", e) + val toast = Toast.makeText(this@MainActivity, "hooked message", Toast.LENGTH_SHORT) + val result = XposedBridge.invokeOriginalMethod(method, toast, emptyArray()) + param.result = result + } + }) + } +} \ No newline at end of file diff --git a/demo/whale_android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/demo/whale_android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/demo/whale_android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/demo/whale_android/app/src/main/res/drawable/ic_launcher_background.xml b/demo/whale_android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/demo/whale_android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/whale_android/app/src/main/res/layout/activity_main.xml b/demo/whale_android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..2005ee9 --- /dev/null +++ b/demo/whale_android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + +