Skip to content

Commit

Permalink
minimal exopackage support
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy authored and Gautam Korlam committed Sep 27, 2016
1 parent 8f8c678 commit 22694e1
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 54 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ android {
versionName "1.0"
buildConfigField "boolean", "CAN_JUMP", "true"
buildConfigField "boolean", "XLOG_ENABLED", "true"
buildConfigField "int", "EXOPACKAGE_FLAGS", "0"
}

signingConfigs {
Expand Down
Binary file added app/libs/buck-android-support.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<application
android:allowBackup="true"
android:name=".MyApp"
android:name=".AppShell"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/com/github/piasy/okbuck/example/AppShell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Piasy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.github.piasy.okbuck.example;

import android.support.multidex.MultiDex;
import com.facebook.buck.android.support.exopackage.ExopackageApplication;

/**
* Created by Piasy{github.com/Piasy} on 16/1/6.
*/

public class AppShell extends ExopackageApplication {

private final boolean mIsExopackageMode;

private static final String APP_NAME = "com.github.piasy.okbuck.example.MyApp";

public AppShell() {
super(APP_NAME, BuildConfig.EXOPACKAGE_FLAGS != 0);
mIsExopackageMode = BuildConfig.EXOPACKAGE_FLAGS != 0;
}

@Override
protected void onBaseContextAttached() {
if (!mIsExopackageMode) {
MultiDex.install(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package com.github.piasy.okbuck.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import butterknife.ButterKnife;
import com.example.hellojni.HelloJni;
import com.github.piasy.okbuck.example.common.Calc;
import com.github.piasy.okbuck.example.common.CalcMonitor;
import com.github.piasy.okbuck.example.dummylibrary.DummyActivity;
import com.github.piasy.okbuck.example.dummylibrary.DummyAndroidClass;
import com.github.piasy.okbuck.example.javalib.DummyJavaClass;
import com.promegu.xlog.base.XLog;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import javax.inject.Inject;

import butterknife.ButterKnife;

/**
* Created by Piasy{github.com/Piasy} on 15/10/3.
*/
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/github/piasy/okbuck/example/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@

package com.github.piasy.okbuck.example;

import android.support.multidex.MultiDexApplication;
import android.app.Application;
import com.facebook.buck.android.support.exopackage.DefaultApplicationLike;
import com.github.promeg.xlog_android.lib.XLogConfig;
import com.squareup.leakcanary.LeakCanary;

/**
* Created by Piasy{github.com/Piasy} on 15/10/6.
*/
public class MyApp extends MultiDexApplication {
public class MyApp extends DefaultApplicationLike {

private final Application mApplication;

public MyApp(Application application) {
mApplication = application;
}

@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.XLOG_ENABLED) {
XLogConfig.config(XLogConfig.newConfigBuilder(this).build());
XLogConfig.config(XLogConfig.newConfigBuilder(mApplication).build());
}
LeakCanary.install(this);
LeakCanary.install(mApplication);
}
}
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ okbuck {
]
linearAllocHardLimit 7194304
primaryDexPatterns = [
'^com/github/piasy/okbuck/example/MyApp^',
'^android/support/multidex/',
'^com/github/piasy/okbuck/example/AppShell^',
'^com/github/piasy/okbuck/example/BuildConfig^',
'^android/support/multidex/',
'^com/facebook/buck/android/support/exopackage/',
'^com/github/promeg/xlog_android/lib/XLogConfig^',
'^com/squareup/leakcanary/LeakCanary^',
]
exopackage true
appClassSource 'src/main/java/com/github/piasy/okbuck/example/AppShell.java'
appLibDependencies = [
'buck-android-support',
'multidex',
]
}

task clean(type: Delete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ public class OkBuckExtension {
* primary dex class patterns.
* */
List<String> primaryDexPatterns = new ArrayList<>()

/**
* whether enable exopackage.
* */
boolean exopackage = false

/**
* exopackage app class source.
* */
String appClassSource = ""

/**
* exopackage app lib dependencies.
* */
List<String> appLibDependencies = new ArrayList<>()

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class OkBuckGradlePlugin implements Plugin<Project> {
okBuckDir, (Map<String, String>) project.okbuck.resPackages,
(String) project.okbuck.keystoreDir, (String) project.okbuck.signConfigName,
(int) project.okbuck.linearAllocHardLimit,
(List<String>) project.okbuck.primaryDexPatterns).
(List<String>) project.okbuck.primaryDexPatterns,
(boolean) project.okbuck.exopackage, (String) project.okbuck.appClassSource,
(List<String>) project.okbuck.appLibDependencies).
generate()
for (Project subProject : buckFiles.keySet()) {
File buckFile = new File(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
package com.github.piasy.okbuck.dependency

import com.github.piasy.okbuck.configs.ThirdPartyDependencyBUCKFile
import com.github.piasy.okbuck.helper.IOHelper
import com.github.piasy.okbuck.helper.ProjectHelper
import com.github.piasy.okbuck.rules.KeystoreRule
import org.apache.commons.io.IOUtils
import org.gradle.api.Project

public final class DependencyProcessor {
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class DependencyProcessor {
}
for (File dependency : aptDependencies.get(project)) {
println "copying ${dependency.absolutePath} into ${dir.absolutePath}"
IOUtils.copy(new FileInputStream(dependency), new FileOutputStream(
IOHelper.copy(new FileInputStream(dependency), new FileOutputStream(
new File(dir.absolutePath + File.separator + dependency.name)))
}
}
Expand All @@ -105,7 +105,8 @@ public final class DependencyProcessor {
if (!dependency.dstDirExists()) {
dependency.createDstDir()
PrintStream printer = new PrintStream(
new File(dependency.dstDirAbsolutePath() + File.separator + "BUCK"))
new File(dependency.dstDirAbsolutePath() + File.separator +
"BUCK"))
new ThirdPartyDependencyBUCKFile(false).print(printer)
printer.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.github.piasy.okbuck.dependency

import org.apache.commons.io.IOUtils
import com.github.piasy.okbuck.helper.IOHelper

/**
* local dependency: jar file.
Expand Down Expand Up @@ -101,7 +101,7 @@ public final class LocalDependency extends Dependency {
mDstDir.mkdirs()
}
println "copying ${mDepFile.absolutePath} into ${mDstDir.absolutePath}"
IOUtils.copy(new FileInputStream(mDepFile), new FileOutputStream(
IOHelper.copy(new FileInputStream(mDepFile), new FileOutputStream(
new File(mDstDir.absolutePath + File.separator + mDepFile.name)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.github.piasy.okbuck.dependency

import org.apache.commons.io.IOUtils
import com.github.piasy.okbuck.helper.IOHelper

/**
* remote dependency: jar/aar file.
Expand All @@ -35,8 +35,10 @@ public final class RemoteDependency extends Dependency {

private final String mResCanonicalName

public RemoteDependency(File depFile, File dstDir, String srcCanonicalName,
String resCanonicalName) {
public RemoteDependency(
File depFile, File dstDir, String srcCanonicalName,
String resCanonicalName
) {
super(srcCanonicalName, depFile)
mDstDir = dstDir
mResCanonicalName = resCanonicalName
Expand Down Expand Up @@ -110,7 +112,7 @@ public final class RemoteDependency extends Dependency {
mDstDir.mkdirs()
}
println "copying ${mDepFile.absolutePath} into ${mDstDir.absolutePath}"
IOUtils.copy(new FileInputStream(mDepFile), new FileOutputStream(
IOHelper.copy(new FileInputStream(mDepFile), new FileOutputStream(
new File(mDstDir.absolutePath + File.separator + mDepFile.name)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ public abstract class BuckFileGenerator {
protected final String mSignConfigName
protected final int mLinearAllocHardLimit
protected final List<String> mPrimaryDexPatterns
protected final boolean mExopackage
protected final String mAppClassSource
protected final List<String> mAppLibDependencies

public BuckFileGenerator(
Project rootProject, DependencyAnalyzer dependencyAnalyzer, File okBuckDir,
Map<String, String> resPackages, String keystoreDir, String signConfigName,
int linearAllocHardLimit, List<String> primaryDexPatterns
int linearAllocHardLimit, List<String> primaryDexPatterns, boolean exopackage,
String appClassSource, List<String> appLibDependencies
) {
mRootProject = rootProject
mDependencyAnalyzer = dependencyAnalyzer
Expand All @@ -57,6 +61,9 @@ public abstract class BuckFileGenerator {
mSignConfigName = signConfigName
mLinearAllocHardLimit = linearAllocHardLimit
mPrimaryDexPatterns = primaryDexPatterns
mExopackage = exopackage
mAppClassSource = appClassSource
mAppLibDependencies = appLibDependencies
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public final class WindowsBuckFileGenerator extends BuckFileGenerator {
public WindowsBuckFileGenerator(
Project rootProject, DependencyAnalyzer dependencyAnalyzer, File okBuckDir,
Map<String, String> resPackages, String keystoreDir, String signConfigName,
int linearAllocHardLimit, List<String> primaryDexPatterns
int linearAllocHardLimit, List<String> primaryDexPatterns, boolean exopackage,
String appClassSource, List<String> appLibDependencies
) {
super(rootProject, dependencyAnalyzer, okBuckDir, resPackages, keystoreDir, signConfigName,
linearAllocHardLimit, primaryDexPatterns)
linearAllocHardLimit, primaryDexPatterns, exopackage, appClassSource,
appLibDependencies)
}

@Override
Expand Down
Loading

0 comments on commit 22694e1

Please sign in to comment.