提交 01b0816a 编写于 作者: J jessyan

improve debug mode

上级 73e4f8c6
<component name="libraryTable">
<library name="leakcanary-android-1.4-beta2">
<CLASSES>
<root url="file://$PROJECT_DIR$/arms/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.4-beta2/res" />
<root url="jar://$PROJECT_DIR$/arms/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.4-beta2/jars/classes.jar!/" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.4-beta2/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.4-beta2/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
......
<component name="libraryTable">
<library name="leakcanary-android-no-op-1.4-beta2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/arms/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android-no-op/1.4-beta2/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/arms/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android-no-op/1.4-beta2/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android-no-op/1.4-beta2/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android-no-op/1.4-beta2/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
......
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -18,7 +18,7 @@ android {
debug {
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "boolean", "USE_CANARY", "false"
buildConfigField "boolean", "USE_CANARY", "true"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
......@@ -57,4 +57,7 @@ dependencies {
provided rootProject.ext.dependencies["javax.annotation"]
compile project(':arms')
compile rootProject.ext.dependencies["paginate"]
debugCompile rootProject.ext.dependencies["canary-debug"]
releaseCompile rootProject.ext.dependencies["canary-release"]
testCompile rootProject.ext.dependencies["canary-release"]
}
......@@ -6,6 +6,7 @@ import com.jess.arms.base.BaseApplication;
import com.jess.arms.http.GlobeHttpHandler;
import com.jess.arms.utils.UiUtils;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -29,6 +30,7 @@ import timber.log.Timber;
*/
public class WEApplication extends BaseApplication {
private AppComponent mAppComponent;
private RefWatcher mRefWatcher;//leakCanary观察器
@Override
public void onCreate() {
......@@ -42,14 +44,33 @@ public class WEApplication extends BaseApplication {
.cacheModule(new CacheModule())//需自行创建
.build();
if (BuildConfig.LOG_DEBUG){//Timber日志打印
if (BuildConfig.LOG_DEBUG) {//Timber日志打印
Timber.plant(new Timber.DebugTree());
}
if (BuildConfig.USE_CANARY){//leakCanary内存泄露检查
LeakCanary.install(this);
}
installLeakCanary();//leakCanary内存泄露检查
}
/**
* 安装leakCanary检测内存泄露
*/
protected void installLeakCanary() {
this.mRefWatcher = BuildConfig.USE_CANARY ? LeakCanary.install(this) : RefWatcher.DISABLED;
}
/**
* 获得leakCanary观察器
*
* @param context
* @return
*/
public static RefWatcher getRefWatcher(Context context) {
WEApplication application = (WEApplication) context.getApplicationContext();
return application.mRefWatcher;
}
@Override
public String getBaseUrl() {
return Api.APP_DOMAIN;
......@@ -57,6 +78,7 @@ public class WEApplication extends BaseApplication {
/**
* 将AppComponent返回出去,供其它地方使用, AppComponent接口中声明的方法返回的实例, 在getAppComponent()拿到对象后都可以直接使用
*
* @return
*/
public AppComponent getAppComponent() {
......
......@@ -2,6 +2,7 @@ package me.jessyan.mvparms.demo.mvp.ui.common;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.mvp.BasePresenter;
import com.squareup.leakcanary.RefWatcher;
import me.jessyan.mvparms.demo.app.WEApplication;
import me.jessyan.mvparms.demo.di.component.AppComponent;
......@@ -20,4 +21,13 @@ public abstract class WEFragment<P extends BasePresenter> extends BaseFragment<P
//提供AppComponent(提供所有的单例对象)给子类,进行Component依赖
protected abstract void setupFragmentComponent(AppComponent appComponent);
@Override
public void onDestroy() {
super.onDestroy();
RefWatcher watcher = WEApplication.getRefWatcher(getActivity());
if (watcher != null) {
watcher.watch(this);
}
}
}
......@@ -59,9 +59,6 @@ dependencies {
compile rootProject.ext.dependencies["okhttp3"]
compile rootProject.ext.dependencies["timber"]
compile rootProject.ext.dependencies["glide"]
debugCompile rootProject.ext.dependencies["canary-debug"]
releaseCompile rootProject.ext.dependencies["canary-release"]
testCompile rootProject.ext.dependencies["canary-release"]
apt rootProject.ext.dependencies["dagger2-apt-compiler"]
compile project(':rxerrorhandler')
}
......@@ -12,7 +12,6 @@ import android.util.AttributeSet;
import android.view.View;
import com.jess.arms.mvp.BasePresenter;
import com.squareup.leakcanary.RefWatcher;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;
......@@ -115,10 +114,6 @@ public abstract class BaseActivity<P extends BasePresenter> extends RxAppCompatA
if (mPresenter != null) mPresenter.onDestroy();//释放资源
ButterKnife.unbind(this);
EventBus.getDefault().unregister(this);
RefWatcher watcher = BaseApplication.getRefWatcher(this);
if (watcher != null) {
watcher.watch(this);
}
}
@Override
......
......@@ -8,8 +8,6 @@ import com.jess.arms.di.module.AppModule;
import com.jess.arms.di.module.ClientModule;
import com.jess.arms.di.module.ImageModule;
import com.jess.arms.http.GlobeHttpHandler;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import java.util.LinkedList;
......@@ -29,7 +27,6 @@ public abstract class BaseApplication extends Application {
static private BaseApplication mApplication;
public LinkedList<BaseActivity> mActivityList;
private ClientModule mClientModule;
private RefWatcher mRefWatcher;//leakCanary观察器
private AppModule mAppModule;
private ImageModule mImagerModule;
protected final String TAG = this.getClass().getSimpleName();
......@@ -48,22 +45,8 @@ public abstract class BaseApplication extends Application {
.build();
this.mAppModule = new AppModule(this);//提供application
this.mImagerModule = new ImageModule();//图片加载框架默认使用glide
}
protected void installLeakCanary() {
this.mRefWatcher = LeakCanary.install(this);
}
/**
* 获得leakCanary观察器
* @param context
* @return
*/
public static RefWatcher getRefWatcher(Context context) {
BaseApplication application = (BaseApplication) context.getApplicationContext();
return application.mRefWatcher;
}
/**
* 提供基础url给retrofit
......
......@@ -7,7 +7,6 @@ import android.view.View;
import android.view.ViewGroup;
import com.jess.arms.mvp.BasePresenter;
import com.squareup.leakcanary.RefWatcher;
import com.trello.rxlifecycle.components.support.RxFragment;
import org.simple.eventbus.EventBus;
......@@ -60,10 +59,6 @@ public abstract class BaseFragment<P extends BasePresenter> extends RxFragment {
super.onDestroy();
if (mPresenter != null) mPresenter.onDestroy();//释放资源
EventBus.getDefault().unregister(this);
RefWatcher watcher = BaseApplication.getRefWatcher(getActivity());
if (watcher != null) {
watcher.watch(this);
}
}
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册