Android Studio 2021.3.1版本如何让你的Notepad跑起来

本博客基于Android Studio 2021.3.1版本构建NotePad

 首先先到llfjfz/NotePad (github.com) --> code -->downlode zip 把本次实验所需的代码下载下来

 解压到你自己目标文件夹然后用Android Studio打开

 打开后是这样的,提示当前版本的gradle与项目不匹配


解决办法 

第一步、我们需要修改三个文件

首先是修改第一个如图所示的build.gradle文件 

 把代码替换为

注意classpath的gradle版本得根据自己的Android Studio,可以打开自己可运行的项目来查看

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

allprojects {
    repositories {
        google()
        mavenCentral ()
        maven {url 'https://dl.bintray.com/jetbrains/anko'}
    }
}

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

 然后是app包下的build.gradle文件

根据自己的安卓版本修改 这三个sdk version(可以查看自己之前运行起来的代码来修改哈)

 

 最后是gradle/warpper/gradel-warpper.propeties

 把'distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip'改成你当前电脑的gradle版本(打开一个可以运行的安卓项目在.gradle文件里可以看到当前支持的gradle版本)

第二步、打开项目文件夹在文件夹下创建一个新的.gradle文件夹,找到一个你已经运行起来的项目的.gradle文件夹里的文件把他粘贴到Notpad项目的.gradle文件夹内

关键是里面要有7.4(或者其他版本)这个文件夹在

 重启你的AS,打开Notepad项目我们可以看到他在自行安装gradle 

安卓完成后我们项目的图标也变成安卓机器人了 

再次运行仍然报错说java运行版本不对

进行第三步、修改Java运行版本

 File-->settings

Build、Execution..-->Build Tools -->Graddle --> Gradle JDK

 选中java11-->apply-->ok

再次运行还是报错

需要第四步、修改manifest文件

首先是报错:As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.

 sdk版本是31或者当你升级到31你新建一个activity时会发现在manifest中的activity属性中默认会出现android:exported="true"属性,其作用就是用来标示:当前Activity是否可以被另一个Application的组件启动:true允许被启动;false不允许被启动。

 

因为这个项目版本较老我们需要手动在activity中添加android:exported="true"属性(一共有四处)

 

 最后是intent-filter missing URL

 将第一个报错区换成以下代码

<intent-filter android:scheme="http"
                tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>

第二个区域换成

<intent-filter android:label="@string/resolve_edit"
                android:scheme="http"
                tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="com.android.notepad.action.EDIT_NOTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>

 

 再次运行就发现我们的项目跑起来啦


感谢你看完,第一次写博客,如果有错误,请指正

如果你跟着步骤把项目跑起来了那么恭喜你,如果你还没有成功运行我这有运行好的(Android Studio2021.3.1),你可以下载使用

链接:https://pan.baidu.com/s/1wPpysMVgv3nNaAr3ZOhmrg?pwd=h0en 
提取码:h0en 


参考资料:https://www.jianshu.com/p/89dc6c109834 

https://www.e-learn.cn/topic/2786626

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值