Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.
关于找不到AsyncTaskCompat类的简单解决办法
1.降低你当前项目的版本;
2.使用新版本中功能相似的方法即可
public final class AsyncTaskCompat {
@Deprecated
public static <Params, Progress, Result> AsyncTask<Params, Progress, Result> executeParallel(
AsyncTask<Params, Progress, Result> task,
Params... params) {
if (task == null) {
throw new IllegalArgumentException("task can not be null");
}
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
return task;
}
private AsyncTaskCompat() {}
}
AsyncTask.execute()
-
Manifest merger failed : android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for
android:exportedwhen the corresponding component has an intent filter defined. See developer.android.com/guide/topic… for details.
在有intent的Activity中,加上android:exported="true"
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-
java.io.FileNotFoundException: /storage/emulated/0/sample_picture_2021-12-20_13-39-32.jpg: open failed: EACCES (Permission denied)
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.i(TAG, "Saving a bitmap to file");
// The camera preview was automatically stopped. Start it again.
mCamera.startPreview();
mCamera.setPreviewCallback(this);
// Write the image in a file (in jpeg format)
try {
FileOutputStream fos = new FileOutputStream(mPictureFileName);
fos.write(data);
fos.close();
} catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
}
没有权限,除了在清单文件中声明权限,动态申请权限之外,Android 10 还需要在清单文件中的 Application 中添加
android:requestLegacyExternalStorage="true"
-
NoClassDefFoundError: Failed resolution of: Landroidx/multidex/MultiDex;
安装闪退
defaultConfig {
multiDexEnabled true
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
-
2 files found with path 'lib/arm64-v8a/libavcodec.so' from inputs:
错误原因是检测到多个libswscale.so文件。 在gradle中添加:
packagingOptions {
pickFirst 'lib/arm64-v8a/libswscale.so'
pickFirst 'lib/arm64-v8a/libavcodec.so'
pickFirst 'lib/arm64-v8a/libavutil.so'
pickFirst 'lib/arm64-v8a/libavformat.so'
pickFirst 'lib/arm64-v8a/libavfilter.so'
pickFirst 'lib/arm64-v8a/libswresample.so'
pickFirst 'lib/arm64-v8a/libavdevice.so'
}
该配置意思是遇到多个只选择第一个
-
FATAL EXCEPTION: OkHttp Dispatcher错误
在OkHttp的onResponse方法,response.body().string()中的 (.string)只能使用一次
-
Only the original thread that created a view hierarchy can touch its views.
不能直接在非主线程里更新UI
-
Failed to allocate a 5018124 byte allocation with 731192 free bytes and 714KB until OOM
【原因】数据文件过大 【方法】:在AndroidMainfest.xml文件里添加代码 android:largeHeap="true"
-
Okhttp websocket CLEARTEXT communication to 192.168.0.143 not permitted by network security policy
-
Unable to establish a connection to adb. Check the Event Log for pos
找到目录中的adb.exe,关掉360手机助手,双击重启
C:\Users\JaredGao\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server
-
Android Glide加载大量图片,出现OOM问题解决方案
1、引入largeHeap属性,让系统为App分配更多的独立内存。
在AndroidManfiest.xml文件的 applaction标签下加入
android:largeHeap="true"
2、设置skipMemoryCache(true),禁止Glide内存缓存。
3、自定义GlideModule。设置MemoryCache和BitmapPool大小。
4、Glide4.0版本后,使用asDrawable代替asBitmap,drawable更省内存。
5、ImageView的scaleType为fitXY时,改为fitCenter/centerCrop/fitStart/fitEnd显示。
6、不使用application作为context。当context为application时,会把imageView是生命周期延长到整个运行过程中,imageView不能被回收,从而造成OOM异常。
7、使用application作为context。但是对ImageView使用弱引用或软引用,尽量使用SoftReference,当内存不足时,将及时回收无用的ImageView。
8、当列表在滑动的时候,调用Glide的pauseRequests()取消请求,滑动停止时,调用resumeRequests()恢复请求。
9、Try catch某些大内存分配的操作。考虑在catch里面尝试一次降级的内存分配操作。例如decode bitmap的时候,catch到OOM,可以尝试把采样比例再增加一倍之后,再次尝试decode。
10、BitmapFactory.Options和BitmapFactory.decodeStream获取原始图片的宽、高,绕过Java层加载Bitmap,再调用Glide的override(width,height)控制显示。
11、图片局部加载。参考:SubsamplingScaleImageView,先将图片下载到本地,然后去加载,只加载当前可视区域,在手指拖动的时候再去加载另外的区域。