Android Studio 迁移、使用新项目遇到BUG总结(持续更新)

本篇为总结在迁移别人项目或新项目时候遇到的bug,希望能帮助到大家

并且持续更新  遇到bug希望各位将bug发在评论或私信

如有侵权 联系删除部分

目录

Build时间过久

Error:(9, 0) Your project path contains non-ASCII characters.

The specified Gradle installation directory XXXX does not exist.

...android.view.InflateException:Binary XML file line #X....

Error occurred during initialization of VM Could not reserve enough space for 2097152KB objec

Manifest merger failed : android:exported needs to be explicitly specified for <activity>

SecurityException: getDataNetworkTypeForSubscriber

 Unable to make field private final java.lang.String java.io.File.path accessible: module java.base d...

Using insecure protocols with repositories, without explicit opt-in, is unsupported.

Service Intent must be explicit 


Build时间过久

build时间超过五分钟甚至以上,尽快修改代码,使用国内镜像

在项目目录下的build.gradle下,

 在repositories {}中添加

maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}

Error:(9, 0) Your project path contains non-ASCII characters.

Android Studio 打开的项目路径中不能含中文!!!甚至有时候你的电脑用户名为中文都不行!

The specified Gradle installation directory XXXX does not exist.

重新选择Gradle目录路径,选到自己的Gradle

打开Setting

 在搜索框找到Gradle,在红框设置目录

...android.view.InflateException:Binary XML file line #X....

首先你要知道错误来源肯定是XML布局文件,然后再往下看 是否能锁定是哪个XML文件,然后打开来,看右上角是否有红色感叹号,若没有可能有点隐蔽

这里是androidx.constraintlayout.widget.ConstraintLayout布局报错,因为该布局大多情况下需要确定约束,没有约束就会报错,需要注意这个经常报错的点

Error occurred during initialization of VM Could not reserve enough space for 2097152KB objec

调试,第一次23-6-14遇到这个问题,一脸懵逼,查了无数资料

方法一(用的就是这个方法解决)

1 找到目录 C:\Users\Administrator\.gradle

但是不一定需要找到Administrator,只需要你去找到.gradle文件夹下即可

2 创建文件:gradle.properties 文件内容如下

org.gradle.jvmargs=-Xmx512m

3 重启Android Studio

方法二(参考文章:https://blog.csdn.net/yjgzhlzh/article/details/87862606

在android studio的bin目录下找到:studio.exe.vmoptions文件。
注意,这里面有两个这样的配置文件:
一个是studio.exe.vmoptions,32位的
一个是studio64.exe.vmoptions的,64位的
系统为多少位就改多少位的文件(同样是以记事本方式打开)

-server
-Xms256m
-Xmx750m 改为1024m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50

Manifest merger failed : android:exported needs to be explicitly specified for <activity>

方法一:降低targetSdkVersion,例如降低至30

 将Manifest中有配置Intent-filter的Activity加上

android:exported属性

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:launchMode="standard"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

SecurityException: getDataNetworkTypeForSubscriber

报错如下,我是迁移老版的百度地图时遇到的问题

报错详细如下:

act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4200010 (has extras) } in com.baidu.mapsdkplatform.comapi.f@e1d6b
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1566)

发现是获取设备网络类型异常

解决办法: 将工程targetsdkversion由30降到29及以下

 Unable to make field private final java.lang.String java.io.File.path accessible: module java.base d...

设置JDK低版本

在你们的电脑里这里可以选择JDK版本  遇事不决选1.8即可

Using insecure protocols with repositories, without explicit opt-in, is unsupported.

新版本中http由于安全性  需要使用https

第一种解决方案是可以加一行参数允许http链接

maven {
		    allowInsecureProtocol = true  //这一行
            url 'xxxxxxx'
      }

第二种方法是将url改为https://xxxxxx

常规出现这种问题的原因就这两种,还有一种配置文件会一层一层引用

android/app/build.gradle -> flutter-tools/flutter.gradle -> C:/Users/XXX/.gradle/init.gradle

其中某一个文件的gradle里出现了http,将其用上面两种问题修正即可解决
参考博主文章:Using insecure protocols with repositories, without explicit opt-in, is unsupported.解决方案_Noxsus的博客-CSDN博客

Service Intent must be explicit 

新版本由于对安全性的考虑   服务意图必须明确

使用以下代码

Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
final Intent intent = new Intent();
        intent.setAction("com.example.raid.service.FIRST_SERVICE");
        intent.setPackage(getPackageName());

com.android.ide.common.signing.KeytoolException: Failed to read key AndroidDebugKey from store

目前碰到这个bug的原因不知道为什么 很懵 如果有人解答交流一下感谢!

解决办法是以下博主博文:

com.android.ide.common.signing.KeytoolException: Failed to read key AndroidDebugKey from store_debug.keystore.lock-CSDN博客

java.lang.NoSuchMethodError

在build.gradle文件中添加

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
}
 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林林要一直努力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值