小米便签从0到1维护教程

小米便签开源社区版从0到1维护教程

1.前置条件-------软件的安装:

开发工具:Android studio

下载Android studio

汉化教程

安装请自行解决

SDK版本以及相关文件

版本为安卓10

SDK Tools:

在这里插入图片描述

小米便签的维护:

下载小米便签的源码:

下载地址:小米便签源码下载

下载完成后的文件结构:
在这里插入图片描述

源文件结构如上图,显而易见,源文件里面没有grandle项目管理工具,因此在用android studio打开的时候,要使用下面的方式

在这里插入图片描述

这种方式会为项目添加一个gradle,打开项目后,等待项目加载完成,然后讲javaJDK 版本更改成JDK8(我在维护的时候这里报过错,没有报错的可以不改)

流程如下:

点击文件,选择项目结构

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

选择SDK Location,再点击Gradle Settings

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

将JDK设置为Java8

在这里插入图片描述

打开项目过后结果:

在这里插入图片描述

此时,项目报错:
Could not find com.android.tools.build:gradle:7.4.2.
Searched in the following locations:

https://jcenter.bintray.com/com/android/tools/build/gradle/7.4.2/gradle-7.4.2.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
Add google Maven repository and sync project
Open File
根据提示,我们在在项目的 build.gradle(Project:Notes) 文件中添加 Google Maven 仓库。你可以在 repositories 块中添加以下代码:
 maven {
            url 'https://dl.google.com/android/maven2'
        }
添加完后如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/android/maven2'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
添加完成后点击右上角的图标:

在这里插入图片描述

此时,开始下载组件:在这里插入图片描述
等待下载,下载过程中,可能会出现问题:
A problem occurred configuring root project 'Notes'.

Could not resolve all files for configuration ':classpath'.
Could not download kotlin-stdlib-common-1.7.10.jar (org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10)
> Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.7.10/kotlin-stdlib-common-1.7.10.jar'.
> Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.7.10/kotlin-stdlib-common-1.7.10.jar'.
> The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.5/userguide/build_environment.html#gradle_system_properties
> Remote host terminated the handshake
这个问题是当前正在使用的仓库已经停止维护,我们使用maven仓库来代替原来的仓库,向项目的 build.gradle(Project:Notes) 文件中,你可以添加以下代码来使用 Maven 中央仓库:
repositories {
    mavenCentral()
}
添加完成后,整个代码如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://dl.google.com/android/maven2'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

现在点击更新,会出现一处错误:
Execution failed for task ':app:mergeDebugResources'.

A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
Could not isolate value com.android.build.gradle.internal.res.Aapt2CompileRunnable$Params_Decorated@7e8ac076 of type Aapt2CompileRunnable.Params
> Could not resolve all files for configuration ':app:detachedConfiguration2'.
> Could not find com.android.tools.build:aapt2:7.4.2-8841542.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/aapt2/7.4.2-8841542/aapt2-7.4.2-8841542.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :app
我们在build.gradle(Project:Notes)文件里面添加一行代码:
  google()
添加后完整代码如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://dl.google.com/android/maven2'
        }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
现在,我们再次构建:映入眼帘的是一个包的错误:

在这里插入图片描述

这个错误产生的原因是在 Android 中,org.apache.http 包已经被废弃,不再推荐在 Android 应用程序中使用,但是我们可以对这个这个包做一个兼容:在build.gradle(Module: App)里面添加
 useLibrary 'org.apache.http.legacy'
完整代码:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.2"

    defaultConfig {
        applicationId "net.micode.notes"
        minSdkVersion 14
        targetSdkVersion 33
        useLibrary 'org.apache.http.legacy'

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

再次点击更新配置

在这里插入图片描述

包的错误暂时解决,不维护网络功能,另外,在GTaskASyncTask.java中,有一个方法报错:

在这里插入图片描述

我们将这个过时的方法更改掉:
//        notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
//                pendingIntent);
        notification.contentIntent = pendingIntent;
        mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
解决这个错误后,还有一个配置文件的错误:

在这里插入图片描述

这个错误是因为在 Android 12 及更高版本中,如果一个组件(如 Activity、Service 或 BroadcastReceiver)定义了 Intent 过滤器,则必须显式指定 android:exported 属性,以确保该组件只能被期望的应用程序或系统组件调用。如果没有指定 android:exported 属性,系统将会认为该组件是公开的,从而可能导致安全漏洞。为了解决这个问题,我们依次在报错的地方加上
android:exported="true"
android:exported="false"
如下:
双击报错位置:

在这里插入图片描述

来到报错的地方,依次更改:

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

打开AndroidManifest.xml文件,可以看到报错的地方:

在这里插入图片描述

控制台显示:

在这里插入图片描述

这个错误是由于 <data> 元素缺少 URI 属性所致。<data> 元素用于指定 Intent 的数据 URI,如果你在 <data> 元素中指定了数据类型(如 android:mimeType 属性),则还必须指定数据 URI。如果没有指定数据 URI,系统将会认为数据缺失,从而导致 “Missing URL” 错误。
将报错的代码替换为:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/text_note" android:scheme="content" android:host="com.example.notes.provider" android:path="/notes" />
    <data android:mimeType="vnd.android.cursor.item/call_note" android:scheme="content" android:host="com.example.notes.provider" android:path="/notes" />
</intent-filter>

现在,我们已经解决了所有让程序停止运行的问题,点击运行一下:

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

这样,小米便签就能够运行起来了

到这里没有运行成功不要灰心~,下面是我打包的运行成功的程序:

点击下载
提取码:v6qd
链接:https://pan.xunlei.com/s/VNVEyleS4tQUNft2-DTE7x30A1#
提取码:v6qd

制作不易,对您有用请留赞~~~~~
  • 15
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值