Android Studio 4.2.1构建项目的问题总结

使用Android Studio 4.2.1 版本新建Project时会出现部分小问题,其他版本若出现类似问题可以参考下以下解决方案。

1、部分.jar文件无法下载;
(1)新建项目Project下的build.gradle内容如下

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

(2)这里可以修改repositories下的内容,改从阿里云仓库下载
阿里云仓库引导:https://developer.aliyun.com/mvn/guide
注意要将 jcenter()注释掉

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven {url 'https://maven.aliyun.com/repository/public/'}
        maven {url 'https://maven.aliyun.com/repository/google/'}
        maven {url 'https://maven.aliyun.com/repository/central/'}
        maven {url 'https://maven.aliyun.com/repository/gradle-plugin/'}

        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {url 'https://maven.aliyun.com/repository/public/'}
        maven {url 'https://maven.aliyun.com/repository/google/'}
        maven {url 'https://maven.aliyun.com/repository/central/'}
        maven {url 'https://maven.aliyun.com/repository/gradle-plugin/'}

        google()
        mavenCentral()
//        jcenter() // Warning: this repository is going to shut down soon
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2、经过以上步骤后,运行程序到Android设备上又会出现以下错误

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to find Build Tools revision 32.0.0

方案一:

修改app目录下的build.gradle内容,降低build-tools版本

  • 修改前:
    在这里插入图片描述

  • 修改后:
    在这里插入图片描述

方案二:
不修改build-tools版本号

(1)在Build栏拉到最上可以看到以下信息;
在这里插入图片描述
(2)这里对比了30.0.3和32.0.0,发现确实是少了一些文件;
在这里插入图片描述
(3)将32.0.0文件夹下缺少的文件从30.0.3下拷贝过来即可,主要有两个文件;

  • dx.bat
    在这里插入图片描述
  • dx.jar
    在这里插入图片描述

(4)再次运行程序后,又出现如下错误;

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.

(5)以上问题官方说明为;

更安全的组件导出

如果您的应用以 Android 12 或更高版本为目标平台,且包含使用 intent 过滤器的 activity、服务或广播接收器,您必须为这些应用组件显式声明 android:exported 属性。

警告:如果 activity、服务或广播接收器使用 intent 过滤器,并且未显式声明 android:exported 的值,您的应用将无法在搭载 Android 12 或更高版本的设备上进行安装。

如果应用组件包含 LAUNCHER 类别,请将 android:exported 设置为 true。在大多数其他情况下,请将 android:exported 设置为 false

(6)在AndroidManifest.xml中设置android:exported的值,因为MainActivity是LAUNCHER类别,所以这里将android:exported 设置为 true。

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值