mirror of
https://gitee.com/replugin/RePlugin.git
synced 2024-12-02 11:48:02 +08:00
Merge pull request #263 from wangfuda/master
resolve : aar complied from build-cache can't be injected by plugin-gradle
This commit is contained in:
commit
9d325d3316
@ -174,13 +174,14 @@ public class ReClassTransform extends Transform {
|
||||
println '>>> Repackage...'
|
||||
includeJars.each {
|
||||
File jar = new File(it)
|
||||
String dir = jar.getParent() + '/' + jar.getName().replace('.jar', '')
|
||||
String JarAfterzip = map.get(jar.getParent() + File.separatorChar + jar.getName())
|
||||
String dirAfterUnzip = JarAfterzip.replace('.jar', '')
|
||||
// println ">>> 压缩目录 $dirAfterUnzip"
|
||||
|
||||
Util.zipDir(dirAfterUnzip, JarAfterzip)
|
||||
|
||||
// println ">>> 压缩目录 $dir"
|
||||
Util.zipDir(dir, jar.absolutePath)
|
||||
|
||||
// println ">>> 删除目录 $dir"
|
||||
FileUtils.deleteDirectory(new File(dir))
|
||||
// println ">>> 删除目录 $dirAfterUnzip"
|
||||
FileUtils.deleteDirectory(new File(dirAfterUnzip))
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +225,7 @@ public class ReClassTransform extends Transform {
|
||||
File jar = input.file
|
||||
if (jar.absolutePath in includeJars) {
|
||||
println ">>> Handle Jar: ${jar.absolutePath}"
|
||||
String dirAfterUnzip = jar.getParent() + File.separatorChar + jar.getName().replace('.jar', '')
|
||||
String dirAfterUnzip = map.get(jar.getParent() + File.separatorChar + jar.getName()).replace('.jar', '')
|
||||
injector.injectClass(pool, dirAfterUnzip, config)
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class Util {
|
||||
File.separator + Hashing.sha1().hashString(jarPath, Charsets.UTF_16LE).toString() + File.separator + "class";
|
||||
if (unzip(jarPath, jarZipDir)) {
|
||||
def jarZip = jarZipDir + ".jar"
|
||||
includeJars << jarZip
|
||||
includeJars << jarPath
|
||||
classPath << jarZipDir
|
||||
visitor.setBaseDir(jarZipDir)
|
||||
Files.walkFileTree(Paths.get(jarZipDir), visitor)
|
||||
@ -97,6 +97,7 @@ public class Util {
|
||||
} else {
|
||||
|
||||
includeJars << jarPath
|
||||
map.put(jarPath, jarPath)
|
||||
|
||||
/* 将 jar 包解压,并将解压后的目录加入 classpath */
|
||||
// println ">>> 解压Jar${jarPath}"
|
||||
|
@ -50,6 +50,12 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
repositories{
|
||||
flatDir{
|
||||
dirs 'libs'
|
||||
}
|
||||
}
|
||||
|
||||
// 这个plugin需要放在android配置之后,因为需要读取android中的配置项
|
||||
apply plugin: 'replugin-plugin-gradle'
|
||||
repluginPluginConfig {
|
||||
@ -62,4 +68,6 @@ dependencies {
|
||||
compile 'com.qihoo360.replugin:replugin-plugin-lib:2.1.6'
|
||||
provided files('libs/fragment.jar')//这个jar就是从Support-fragment中提取出来的并非特制包目的是为了骗过编译期
|
||||
provided files('libs/common-utils-lib-1.0.0.jar')//这个jar就是从Host的utils中编译生成的,其目的是为了骗过编译期
|
||||
compile(name:'plugin-library',ext:'aar')//sample:compile aar
|
||||
|
||||
}
|
||||
|
BIN
replugin-sample/plugin/plugin-demo1/app/libs/plugin-library.aar
Normal file
BIN
replugin-sample/plugin/plugin-demo1/app/libs/plugin-library.aar
Normal file
Binary file not shown.
@ -48,6 +48,7 @@ import com.qihoo360.replugin.sample.demo1.activity.theme.ThemeBlackNoTitleBarFul
|
||||
import com.qihoo360.replugin.sample.demo1.activity.theme.ThemeDialogActivity;
|
||||
import com.qihoo360.replugin.sample.demo1.service.PluginDemoService1;
|
||||
import com.qihoo360.replugin.sample.demo2.IDemo2;
|
||||
import com.qihoo360.replugin.sample.library.LibMainActivity;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@ -305,6 +306,17 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// =========
|
||||
// aar
|
||||
// =========
|
||||
mItems.add(new TestItem("AAR Activity: Standard", new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(v.getContext(), LibMainActivity.class);
|
||||
v.getContext().startActivity(intent);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static final int REQUEST_CODE_DEMO2 = 0x021;
|
||||
|
1
replugin-sample/plugin/plugin-demo1/library/.gitignore
vendored
Normal file
1
replugin-sample/plugin/plugin-demo1/library/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
43
replugin-sample/plugin/plugin-demo1/library/build.gradle
Normal file
43
replugin-sample/plugin/plugin-demo1/library/build.gradle
Normal file
@ -0,0 +1,43 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.0"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
|
||||
//task to copy library to libs
|
||||
task copyLibrary(type: Copy) {
|
||||
|
||||
from('build/outputs/aar/library-debug.aar')
|
||||
into('../app/libs')
|
||||
///Rename the aar
|
||||
rename('library-debug.aar', 'plugin-library.aar')
|
||||
}
|
||||
|
||||
copyLibrary.dependsOn(build)
|
25
replugin-sample/plugin/plugin-demo1/library/proguard-rules.pro
vendored
Normal file
25
replugin-sample/plugin/plugin-demo1/library/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in D:\Android\sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# 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
|
@ -0,0 +1,26 @@
|
||||
package com.qihoo360.replugin.sample.library;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumentation test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.qihoo360.replugin.sample.library.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
package="com.qihoo360.replugin.sample.library">
|
||||
|
||||
<application android:allowBackup="false" android:label="@string/app_name"
|
||||
android:supportsRtl="true">
|
||||
<activity
|
||||
android:name=".LibMainActivity"
|
||||
android:label="@string/app_name">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,14 @@
|
||||
package com.qihoo360.replugin.sample.library;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class LibMainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.lib_activity_main);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="AAR Activity:\nStandard"
|
||||
android:textSize="30sp"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<include layout="@layout/content_lib_main" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">library</string>
|
||||
</resources>
|
@ -0,0 +1,17 @@
|
||||
package com.qihoo360.replugin.sample.library;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
@ -14,4 +14,4 @@
|
||||
* the License.
|
||||
*/
|
||||
|
||||
include ':app'
|
||||
include ':app', ':library'
|
||||
|
Loading…
Reference in New Issue
Block a user