Android 遇到的一些问题

问题(20220720)

新创建的项目报下面的错误
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

大概意思是 目标版本为android12,需要再配置android:exported属性。一般是你的工程版本为31或31以上才会出现该问题

解决方案:
1、可以将buildToolsVersion改为31以下
2、如果不改版本的话,需要在AndroidManifest.xml中的activity里面配置 android:exported=“true”。例如:

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.App">
        <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>
    </application>

问题(20220720)

Android studio Installed Build Tools revision 31.0.0 is corrupted. Remove and install again
大致意思是:31.0.0的这个版本已经损坏,需要移除重新安装下。
新创建的项目突然报这个错误,我看了下AndroidSDK是有31.0.0的这个版本。
解决方案:
1、按官方提示的来:卸载重新安装下31.0.0的这个版本。
在这里插入图片描述
2、如果按照上面的方式卸载重新安装还是不行的话。可以尝试下面的方法

//1、找到你的SDK目录,比如我的目录
"D:\Android\SDK\build-tools\31.0.0"

//2、找到下面2几个文件改下名字(如下图所示)
a 修改d8.bat 为 dx.bat
b 修改d8.jar 为 dx.jar

//3、重启下AS

在这里插入图片描述在这里插入图片描述

1、应用未安装,如下图所示

在这里插入图片描述
可能原因:

 1、正要安装的APP的自定义权限与手机上已有APP的自定义权限名字相同,但两个APP具有不同的签名信息导致安装失败。
 2、Android L(android 5.0)以上系统限制。

解决:

 1、不同渠道包保证签名一致;
 2、若只需要验证当前渠道包,可以直接先卸载旧游戏包。

2、在运行时,提示程序包android.support.multidex不存在 找不到符号 类 MultiDexApplication等一大堆信息。

在这里插入图片描述
解决方案:
可能是没有引用multidex库。需要再module中的build.gradle文件中添加。

dependencies {
	    implementation 'com.android.support:multidex:1.0.0'
}

3、Glide加载图片时出现ou cannot start a load for a destroyed activity异常的问题

导致原因:当前activity已经关闭了,glide还在加载数据。
解决方案:在glide加载图片前,先判断下当前activity/fragment是否已经销毁了。
判断activity是否已经被销毁,可以参考我的另外一篇博客
https://blog.csdn.net/weixin_42273922/article/details/103734362

4、在进行图片压缩的时候出现java.lang.IllegalArgumentException: quality must be 0…100

源码说明,我们通过第二个参数可以看到,压缩比例范围是0-100且是闭区间。[0,100]。

    /**
     * Write a compressed version of the bitmap to the specified outputstream.
     * If this returns true, the bitmap can be reconstructed by passing a
     * corresponding inputstream to BitmapFactory.decodeStream(). Note: not
     * all Formats support all bitmap configs directly, so it is possible that
     * the returned bitmap from BitmapFactory could be in a different bitdepth,
     * and/or may have lost per-pixel alpha (e.g. JPEG only supports opaque
     * pixels).
     *
     * @param format   The format of the compressed image
     * @param quality  Hint to the compressor, 0-100. 0 meaning compress for
     *                 small size, 100 meaning compress for max quality. Some
     *                 formats, like PNG which is lossless, will ignore the
     *                 quality setting
     * @param stream   The outputstream to write the compressed data.
     * @return true if successfully compressed to the specified stream.
     */
    @WorkerThread
    public boolean compress(CompressFormat format, int quality, OutputStream stream) {
        checkRecycled("Can't compress a recycled bitmap");
        // do explicit check before calling the native method
        if (stream == null) {
            throw new NullPointerException();
        }
        if (quality < 0 || quality > 100) {
            throw new IllegalArgumentException("quality must be 0..100");
        }
        StrictMode.noteSlowCall("Compression of a bitmap is slow");
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "Bitmap.compress");
        boolean result = nativeCompress(mNativePtr, format.nativeInt,
                quality, stream, new byte[WORKING_COMPRESS_STORAGE]);
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        return result;
    }

解决方案
只要控制在[0,100]的比例范围内即可。

5、问题描述:Unable to add window token android.os.BinderProxy@a81b65d is not valid; is your activity running?

原因一般是展示dialog的时候用的是异步,或者是另开一个线程。当Activity已经关闭,才调用dialog.show(),此时Activity已经不存在,就会报错。

解决方案:可以参考问题3的解决方案即可。只需在show()之前,判断当前activity是否存在。
https://blog.csdn.net/weixin_42273922/article/details/103734362

6、问题描述:dl.google.com:443 failed to respond…

部分错误日志

FAILURE: Build failed with an exception.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.1.2.
     Required by:
       project :
      > Could not resolve com.android.tools.build:gradle:3.1.2.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom'.
               > dl.google.com:443 failed to respond
      > Could not resolve com.android.tools.build:gradle:3.1.2.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom'.
               > jcenter.bintray.com:443 failed to respond

   ..............

解决方案:打开settings—>build,execution,deplogment—>gradle—>android studio -->开启。
如下图所示
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值