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:
Jiongxuan Zhang 2017-07-28 18:31:00 +08:00 committed by GitHub
commit 9d325d3316
16 changed files with 198 additions and 9 deletions

View File

@ -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"
// println ">>> 压缩目录 $dir"
Util.zipDir(dir, jar.absolutePath)
Util.zipDir(dirAfterUnzip, JarAfterzip)
// 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)
}
}

View File

@ -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}"

View File

@ -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
}

View File

@ -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;

View File

@ -0,0 +1 @@
/build

View 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)

View 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

View File

@ -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());
}
}

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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>

View File

@ -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>

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">library</string>
</resources>

View File

@ -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);
}
}

View File

@ -14,4 +14,4 @@
* the License.
*/
include ':app'
include ':app', ':library'