我在开发中使用Logger库,并在Application类中配置它:
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(LogLevel.NONE); // default LogLevel.FULL
Run Code Online (Sandbox Code Playgroud)
LogLevel是一个枚举(在Logger库中).
但我想根据我的gradle构建类型自动设置日志级别; 做那样的事情:
buildTypes {
debug {
debuggable true
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.FULL
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.NONE
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(BuildConfig.LOGGER_LEVEL); // default LogLevel.FULL
Run Code Online (Sandbox Code Playgroud)
但它不起作用:
错误:(31,0)没有这样的属性:类没有:org.gradle.api.logging.LogLevel
它与FULL枚举值相同.
谢谢你的帮助!
我3天前已经迁移到SDK Android 27.1.0,并且有一些像这样的崩溃,我无法理解为什么.它(目前)出现在Android 8和6上.
BadParcelableException ClassNotFoundException when unmarshalling: android.support.v4.app.FragmentManagerState android.support.v4.app.Fragment.setUserVisibleHint
android.os.Parcel.readParcelableCreator (Parcel.java:2916)
android.os.Parcel.readParcelable (Parcel.java:2842)
android.os.Parcel.readValue (Parcel.java:2745)
android.os.Parcel.readArrayMapInternal (Parcel.java:3114)
android.os.BaseBundle.initializeFromParcelLocked (BaseBundle.java:273)
android.os.BaseBundle.unparcel (BaseBundle.java:226)
android.os.BaseBundle.putBoolean (BaseBundle.java:532)
arrow_right
android.support.v4.app.Fragment.setUserVisibleHint (Fragment.java:960)
android.support.v4.app.FragmentStatePagerAdapter.instantiateItem (FragmentStatePagerAdapter.java:121)
android.support.v4.view.ViewPager.addNewItem (ViewPager.java:1004)
android.support.v4.view.ViewPager.populate (ViewPager.java:1218)
android.support.v4.view.ViewPager.populate (ViewPager.java:1086)
android.support.v4.view.ViewPager$3.run (ViewPager.java:267)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
android.view.Choreographer.doCallbacks (Choreographer.java:723)
android.view.Choreographer.doFrame (Choreographer.java:655)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
android.os.Handler.handleCallback (Handler.java:790)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6494)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Run Code Online (Sandbox Code Playgroud)
这是我的适配器:
public abstract class CalendarPagerAdapter extends FragmentStatePagerAdapter {
private static final String TAG = LogUtils.makeLogTag(CalendarPagerAdapter.class);
protected DateTime mDateTime;
private final int …Run Code Online (Sandbox Code Playgroud) 上周我将Android Studio从2.x更新到3.x. 项目迁移是完美的,构建很棒.现在,从2个小时开始,我无法解释为什么,我无法构建,我现在在Glide上有这个错误:
错误:(26,22)错误:找不到符号类GlideApp
之前一切都很好,我没有改变任何东西(gradle或配置),现在出现这个错误......
有关Glide的信息,请参阅我的Gradle:
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
compile 'com.github.bumptech.glide:okhttp3-integration:4.0.0-RC1'
Run Code Online (Sandbox Code Playgroud)
GlideApp文件自动生成(我检查过).
所以,这是一个疯狂的情况.非常感谢你们!
有时在我的Samsung S3(4.4 SDK版本)上有这个例外:
由java.lang.ClassNotFoundException引起:在路径上没有找到类"android.graphics.drawable.Icon":DexPathList [[zip file"/data/app/com.xxxx-1.apk",zip file"/ data /data/com.xxxx/code_cache/secondary-dexes/com.xxxx-1.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.xxxx-1,/ vendor/lib,/ system/lib]]在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
我完全遵循这些元素:https://developer.android.com/studio/build/multidex.html
在我的三星S5(6 SDK)上,没有问题.
我无法从Firebase控制台(Crashlytics视图)中看到崩溃的详细信息.
这个默认视图显示了集成Crashlytics的3个步骤:
是否有特定的设置来启用Crashlytics视图?
我使用了Crashlytics 1年,它完美无缺.我只想将所有数据报告迁移到Firebase中.我遵循了这个教程:https://proandroiddev.com/migrating-crashlytics-to-the-firebase-console-5e05b6ff8c12
从Firebase上的项目概述,我可以看到崩溃(昨天为我的测试完成),如果我点击它有相同的默认视图.
我想确保一个String只包含字母字符(如特殊字符"é", "è", "ç", "Ç", "ï"等).
我做到了,但是使用特殊字符返回false ...
if (myString.matches("^[a-zA-Z]+$")) {
return true;
}
Run Code Online (Sandbox Code Playgroud)
多谢你们!
我想测试一个包含变量PlateformConnect的片段UserConnectFragment.这个类有一个初始化Facebook SDK的方法:
@Override
public void create() {
FacebookSdk.sdkInitialize(MyApplication.getInstance().getApplicationContext());
}
Run Code Online (Sandbox Code Playgroud)
我用MyApplication类扩展了Android应用程序.
在UserConnectFragment中,我使用PlateformConnect:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Must be done before the content view assignement!
PlateformConnect.getInstance().create();
...
Run Code Online (Sandbox Code Playgroud)
在我的Robolectric类测试中:
@Before
public void setUp() throws Exception {
// Create basic activity, and add fragment
mActivity = Robolectric.buildActivity(FragmentActivity.class).create().start().resume().get();
mUserConnectFragment = new UserConnectFragment();
addMapFragment(mActivity, mUserConnectFragment);
//mLoginButton = (Button) mActivity.findViewById(R.id.facebook_button);
}
Run Code Online (Sandbox Code Playgroud)
此测试运行时发生崩溃:
java.lang.NullPointerException
at com.xxx.yyyy.ui.intro.UserConnectFragment.onViewCreated(UserConnectFragment.java:77)
Run Code Online (Sandbox Code Playgroud)
出现此错误是因为我使用:
MyApplication.getInstance().getApplicationContext()
Run Code Online (Sandbox Code Playgroud)
...和getInstance()返回null.
在我的应用程序中,我在很多类中使用MyApplication.getInstance(),那么我该如何使用Robolectric进行测试?
多谢你们!
是否可以将 Class 类型放在 Bundle 中?
public static <T> Intent newInstance(Class<T> EventClass) {
Bundle args = new Bundle();
args.putXXXX(EventClass);
Intent intent = new Intent(MyApplication.getInstance(), MyActivity.class);
intent.putExtras(args);
return intent;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你们 !
我想在布局的右上角做一个带三角形的按钮:
我已经开始没有这个三角形的布局了:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:paddingLeft="@dimen/keyline_1"
android:paddingRight="@dimen/keyline_2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/grey"
android:text="DESCRIPTION"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="@dimen/keyline_4"
android:textColor="@color/grey"
android:text="info"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/grey"
android:text="TITLE"/>
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我遵循了 Google Developer Doc 中的所有最佳实践:https : //developer.android.com/google/play/billing/billing_library_overview
我在 Beta 测试模式下推送我的应用程序。一切正常,除了每次我进行应用内(或订阅)购买时,我都会收到一封电子邮件(购买确认,好的),然后 5-6 分钟后我收到另一封电子邮件(总是来自 Google)通知我的购买已被取消了...
我不想自动取消。为什么是这个过程?
非常感谢你们!