简书转掘金了,简书广告太多,受不了了 原链javascript
ButterKnife8.0以后依赖注入以后报空指针错误php
解决方式:由于8.0以后运行时代码插件更新,因此须要配置java
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
复制代码
不过最简单的办法是除了依赖Butterknife以外,依赖android
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
复制代码
Glide加载图片报错You must not call setTag() on a view Glide is targetingapache
解决方式:出现这种错误每每是由于使用了ListView或者RecyclerView,其Item的布局进行了简写,解决方法只须要将Item增长父布局便可api
Glide加载大图出现拉伸问题. 首先将本身的imageview的scaleType属性设置为centerCrop,而后使用glide的时候以下设置浏览器
Glide.with(context).load(url).asBitmap().centerCrop().placeholder(R.drawable.defaultpic).into(imageview);
复制代码
Glide V4依赖出错bash
提示Support资源找不到,只须要升级一下Support版本就能够,最好为26以上app
implementation 'com.android.support:appcompat-v7:27+'
implementation 'com.android.support:design:27.+'
复制代码
Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018less
提示将compile替换为implementation,而且compile将于2018年末进行删除
The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.
instrumentTest在更新以后已通过时,用androidTest替换便可
DSL element 'DexOptions.incremental' is obsolete and will be removed at the end of 2018
将incremental = true删除便可.
Toolbar内部左侧始终有一段空白,没法填充
在toolbar布局中加入以下代码便可解决
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
复制代码
自定义对话框顶部始终有一个白边,底部线性布局嵌套TextView始终无圆角
白边问题ImageView添加属性
android:adjustViewBounds="true"
无圆角问题缘由:把圆角shape文件设置给了线性布局,修改设置给textview后正常
复制代码
OPPO手机拍照成功以后点击肯定没反应,通过核查发现是保存图片的路径问题致使的,将路径改成以下后正常
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()
复制代码
Android嵌套H5,经过javascript调用H5没法显示内容,将H5的UL改成div包裹UL恢复正常
打包混淆以后EventBus报错,在混淆文件中加入以下代码正常
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
复制代码
尝试使用Dagger2时报错
Could not find method apt() for arguments [com.google.dagger:dagger-compiler:2.6] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
复制代码
将依赖中的apt...改成annotationProcessor...
参考资料 : With android gradle plugin 2.2.0 release, the android-apt plugin is no longer needed for annotation processing. The apt function was included in the latest android gradle plugin which called annotationProcessor.
compile 'com.google.dagger:dagger:2.6'
annotationProcessor "com.google.dagger:dagger-compiler:2.6"
复制代码
Android ContextThemeWrapper cannot be cast to android.app.Activity
加入如下代码:
private static Activity checkActivity(Context context) {
if (context == null){
return null;
} else if (context instanceof Activity){
return (Activity)context ;
} else if (context instanceof ContextWrapper){
return checkActivity(((ContextWrapper)context).getBaseContext());
}
return null;
}
复制代码
调用时:
TextView tvView = new TextView(checkActivity(getContext()));
复制代码
去除腾讯X5浏览器的滑动块(原生去除滑动块方法对X5无效)
if (infoWebView.getX5WebViewExtension() != null) {
infoWebView.getX5WebViewExtension().setHorizontalScrollBarEnabled(false);//水平不显示滚动按钮
infoWebView.getX5WebViewExtension().setVerticalScrollBarEnabled(false); //垂直不显示滚动按钮
}
复制代码
判断当前处于活动的Activity是否包含指定Activity
/** * 判断MainActivity是否活动 * * @param activityName 要判断Activity,最好传全包名 * @return boolean */
private boolean isMainActivityAlive(Context context, String activityName) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(100);
for (ActivityManager.RunningTaskInfo info : list) {
// 注意这里的 topActivity 包含 packageName和className,能够打印出来看看
if (info.topActivity.toString().contains(activityName) || info.baseActivity.toString().contains(activityName)) {
LogUtils.e(TAG, info.topActivity.getPackageName() + " info.baseActivity.getPackageName()=" + info.baseActivity.getPackageName());
return true;
}
}
return false;
}
复制代码
AS项目编译报错
Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.
复制代码
在gradle-wrapper.properties 文件,修改distributionUrl 参数,低于4.6便可
2018年12月18日11:31:06 Android P强制接受HTTP: 新建文件 res -> xml ->network_security_config.xml,并填写以下内容:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
复制代码
在AndroidManifest ->application节点加入:
android:networkSecurityConfig="@xml/network_security_config"
复制代码
Android P继续使用HTTPClient 给老项目升级到P,项目报错:
java.lang.RuntimeException: Stub!
  at org.apache.http.message.BasicNameValuePair.<init>(BasicNameValuePair.java:6)
复制代码
在Android P以后,org.apache.http.legacy 库将从 bootclasspath 中删除,因此没法继续使用.官方文档:
小声BB(还能怎么办,强制接受吧......) 继续使用方法:在AndroidManifest ->application节点内加入:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
复制代码
报错 : Manifest merger failed with multiple errors, see logs
复制代码
解决方法:切换到Terminal,运行以下命令后便可看到详细错误
gradlew processDebugManifest --stacktrace
复制代码
ERROR: Failed to resolve: support-media-compat
复制代码
缘由:莫名其妙的报错,莫名其妙的被墙,莫名其妙的糟心 解决方法: 项目build文件中注释:
mavenCentral()
google()
jcenter()
复制代码
换为
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
复制代码
最后应为以下:
buildscript {
repositories {
// jcenter()
// mavenCentral()
// google()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}
dependencies {
...
}
}
allprojects {
repositories {
// mavenCentral()
// jcenter()
// google()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
...
}
}
复制代码
EditText的clearFocus()方法无效 经过查看源码发现,clearFocus并非真的清除焦点,而是在整个布局中遍历获取focusInTouchMode为true的View,若是EditText为第一个,就又从新设置了焦点,陷入了死循环,因此才会看上去无效,解决方法只须要将EditText以前的view设置以下属性
android:focusableInTouchMode="true"
复制代码
AndroidManifast警告GoogleAppIndexingWarning App is not indexable by Google Search
<action android:name="android.intent.action.VIEW" />
复制代码
或直接进行Alt+Enter忽略
从后台切换程序后,页面从新加载报错
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.support.v7.widget.Toolbar$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/toolbar. Make sure other views do not use the same id 复制代码
报错是说页面从新加载时,toolbar的id是重复的,百思不得其解,百度发现一些相同的问题,无解,后偶然间发现,布局中include的toolbar的id和toolbar.xml中的toolbar的id都是toolbar,将内部的toolbar的id进行修改后,解决问题.
<include android:id="@+id/toolbar" layout="@layout/toolbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" binding:toolbarViewModel="@{mainViewModel.toolbarViewModel}" />
复制代码
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="0dp" android:layout_height="49dp" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" app:contentInsetLeft="0dp" app:contentInsetStart="0dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
复制代码
上边的id重复了,致使的问题