Android Studio 2024 小米便签项目摆设

打印 上一主题 下一主题

主题 846|帖子 846|积分 2538

目次
前言
一、软件安装
二、下载小米便签项目源码
三、新建项目工程
四、将下载的项目源码导入到Android项目的对应目次及文件下
五、解决错误
六、摆设假造机
七、项目展示



前言

经过一学期的学习,《软件工程》这门课程已靠近尾声。由此,老师给我们布置了一个实践使命——小米便签项目。具体是由小组合作,摆设项目和上传长途git仓库。因为在实践完成过程中发现会出现很多问题,故编写这这篇博客,用来记录问题。希望也能帮到大家,谢谢!
一、软件安装

这里先容下我用的Android Studio的版本是2024.2.1,SDK版本为API 24,Gradle版本为8.9。
Android Studio官网下载链接https://developer.android.google.cn/studio?hl=en,找到对应版本举行下载,具体的安装方式推荐大家看这篇https://blog.csdn.net/m0_73909612/article/details/137931888。
二、下载小米便签项目源码

首先我们从github上的开源代码仓库上下载小米便签的源码包。下载地点:https://codeload.github.com/MiCode/Notes/zip/master,然后将下载的zip包举行解压。

三、新建项目工程

双击打开Android Studio软件,选择New Project,选择Empty Views Activity,新建一个空项目:

按照下面图示举行配置:

新创建好的项目目次如下:

四、将下载的项目源码导入到Android项目的对应目次及文件下

把原项目的代码内容搬到新建的项目工程中去:
1.首先把项目 Notes-master\src\net\micode\notes 下的包全部导入 Android Studio 的 net\micode\notes 下:

2.把 Notes-master\res 目次下的包全部导入 Android Studio 的 res 中:
(重复的文件选择替换掉这些文件)

3.将以下代码导入到AndroidManifest.xml文件中:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools">
  4.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  5.     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
  6.     <uses-permission android:name="android.permission.INTERNET" />
  7.     <uses-permission android:name="android.permission.READ_CONTACTS" />
  8.     <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
  9.     <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
  10.     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  11.     <uses-permission android:name="android.permission.USE_CREDENTIALS" />
  12.     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  13.     <application
  14.         android:allowBackup="true"
  15.         android:dataExtractionRules="@xml/data_extraction_rules"
  16.         android:fullBackupContent="@xml/backup_rules"
  17.         android:icon="@mipmap/ic_launcher"
  18.         android:label="@string/app_name"
  19.         android:roundIcon="@mipmap/ic_launcher_round"
  20.         android:supportsRtl="true"
  21.         android:theme="@style/Theme.Notesmaster"
  22.         tools:targetApi="31">
  23.         <activity
  24.             android:name=".ui.NotesListActivity"
  25.             android:configChanges="keyboardHidden|orientation|screenSize"
  26.             android:label="@string/app_name"
  27.             android:launchMode="singleTop"
  28.             android:theme="@style/NoteTheme"
  29.             android:uiOptions="splitActionBarWhenNarrow"
  30.             android:windowSoftInputMode="adjustPan"
  31.             android:exported="true">
  32.             <intent-filter>
  33.                 <action android:name="android.intent.action.MAIN" />
  34.                 <category android:name="android.intent.category.LAUNCHER" />
  35.             </intent-filter>
  36.         </activity>
  37.         <activity
  38.             android:name=".ui.NoteEditActivity"
  39.             android:configChanges="keyboardHidden|orientation|screenSize"
  40.             android:launchMode="singleTop"
  41.             android:theme="@style/NoteTheme"
  42.             android:exported="true">
  43.             <intent-filter>
  44.                 <action android:name="android.intent.action.VIEW" />
  45.                 <category android:name="android.intent.category.DEFAULT" />
  46.                 <data android:mimeType="vnd.android.cursor.item/text_note" />
  47.                 <data android:mimeType="vnd.android.cursor.item/call_note" />
  48.             </intent-filter>
  49.             <intent-filter>
  50.                 <action android:name="android.intent.action.INSERT_OR_EDIT" />
  51.                 <category android:name="android.intent.category.DEFAULT" />
  52.                 <data android:mimeType="vnd.android.cursor.item/text_note" />
  53.                 <data android:mimeType="vnd.android.cursor.item/call_note" />
  54.             </intent-filter>
  55.             <intent-filter>
  56.                 <action android:name="android.intent.action.SEARCH" />
  57.                 <category android:name="android.intent.category.DEFAULT" />
  58.             </intent-filter>
  59.             <meta-data
  60.                 android:name="android.app.searchable"
  61.                 android:resource="@xml/searchable" />
  62.         </activity>
  63.         <provider
  64.             android:name="net.micode.notes.data.NotesProvider"
  65.             android:authorities="micode_notes"
  66.             android:multiprocess="true" />
  67.         <receiver
  68.             android:name=".widget.NoteWidgetProvider_2x"
  69.             android:label="@string/app_widget2x2"
  70.             android:exported="true">
  71.             <intent-filter>
  72.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
  73.                 <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
  74.                 <action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
  75.             </intent-filter>
  76.             <meta-data
  77.                 android:name="android.appwidget.provider"
  78.                 android:resource="@xml/widget_2x_info" />
  79.         </receiver>
  80.         <receiver
  81.             android:name=".widget.NoteWidgetProvider_4x"
  82.             android:label="@string/app_widget4x4"
  83.             android:exported="true">
  84.             <intent-filter>
  85.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
  86.                 <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
  87.                 <action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
  88.             </intent-filter>
  89.             <meta-data
  90.                 android:name="android.appwidget.provider"
  91.                 android:resource="@xml/widget_4x_info" />
  92.         </receiver>
  93.         <receiver android:name=".ui.AlarmInitReceiver"
  94.             android:exported="true">
  95.             <intent-filter>
  96.                 <action android:name="android.intent.action.BOOT_COMPLETED" />
  97.             </intent-filter>
  98.         </receiver>
  99.         <receiver
  100.             android:name="net.micode.notes.ui.AlarmReceiver"
  101.             android:process=":remote" >
  102.         </receiver>
  103.         <activity
  104.             android:name=".ui.AlarmAlertActivity"
  105.             android:label="@string/app_name"
  106.             android:launchMode="singleInstance"
  107.             android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" >
  108.         </activity>
  109.         <activity
  110.             android:name="net.micode.notes.ui.NotesPreferenceActivity"
  111.             android:label="@string/preferences_title"
  112.             android:launchMode="singleTop"
  113.             android:theme="@android:style/Theme.Holo.Light" >
  114.         </activity>
  115.         <service
  116.             android:name="net.micode.notes.gtask.remote.GTaskSyncService"
  117.             android:exported="false" >
  118.         </service>
  119.         <meta-data
  120.             android:name="android.app.default_searchable"
  121.             android:value=".ui.NoteEditActivity" />
  122.         
  123. <!--        <activity-->
  124. <!--            android:name=".MainActivity"-->
  125. <!--            android:exported="true">-->
  126. <!--            <intent-filter>-->
  127. <!--                <action android:name="android.intent.action.MAIN" />-->
  128. <!--                <category android:name="android.intent.category.LAUNCHER" />-->
  129. <!--            </intent-filter>-->
  130. <!--        </activity>-->
  131.         
  132.     </application>
  133. </manifest>
复制代码
五、解决错误

导入完成之后,点击小锤子(Make Model '......')构建项目,然后本次实践使命的重头戏来了,你会发现有很多报错,解决一个来一个。不要慌,我们一个一个来解决:
1.依靠下载:
        源码依靠于一个httpcomponents-client组件,以执行网络服务,这里我们需要去下载依靠:
下载链接:https://dlcdn.apache.org//httpcomponents/httpclient/binary/httpcomponents-client-4.5.14-bin.zip
然后将下载好后的zip包解压放在下一目次:

在Android Studio中导入依靠:
选择选择File -> Project Structure ->Dependencies-> All Dependencies -> +->

填写绝对路径,这里根据自己下载的依靠库路径填写。

导入后,会发现build.gradle多了以下内容:

2.报错:找不到符号 notification.setLatestEventInfo...
这时,会出现以下错误:
错误: 找不到符号 notification.setLatestEventInfo(......)
  1. D:\Code\AndroidCode\Notesmaster\app\src\main\java\net\micode\notes\gtask\remote\GTaskASyncTask.java:80: 错误: 找不到符号
  2.         notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
  3.                     ^
  4.   符号:   方法 setLatestEventInfo(Context,String,String,PendingIntent)
  5.   位置: 类型为Notification的变量 notification
复制代码


解决方法==>解释以下代码:

修改为:
  1. private void showNotification(int tickerId, String content) {
  2.     PendingIntent pendingIntent;
  3.     if (tickerId != R.string.ticker_success) {
  4.         pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
  5.                 NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE);
  6.     } else {
  7.         pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
  8.                 NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE);
  9.     }
  10.     Notification.Builder builder = new Notification.Builder(mContext)
  11.             .setAutoCancel(true)
  12.             .setContentTitle(mContext.getString(R.string.app_name))
  13.             .setContentText(content)
  14.             .setContentIntent(pendingIntent)
  15.             .setWhen(System.currentTimeMillis())
  16.             .setOngoing(true);
  17.     Notification notification=builder.getNotification();
  18.     mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
  19. }
复制代码
3.报错:switch语句报错Constant expression required
  1. D:\Code\AndroidCode\Notesmaster\app\src\main\java\net\micode\notes\ui\NoteEditActivity.java:511: 错误: 需要常量表达式
  2.             case R.id.menu_new_note:
复制代码


解决办法参考链接:https://blog.csdn.net/mjh1667002013/article/details/134763804
4.报错:jar包冲突

这里是因为我们刚才导入的依靠包有问题,所以在build.gradle里举行修改:
这部分代码有误

修改成:
  1. dependencies {
  2.     implementation(libs.appcompat)
  3.     implementation(libs.material)
  4.     implementation(libs.activity)
  5.     implementation(libs.constraintlayout)
  6.     implementation(files("E:\\\\mi\\\\Notesmaster\\\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-osgi-4.5.14.jar"))
  7.     implementation(files("E:\\\\mi\\\\Notesmaster\\\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-win-4.5.14.jar"))
  8.     implementation(files("E:\\\\mi\\\\Notesmaster\\\\httpcomponents-client-4.5.14-bin\\lib\\httpcore-4.4.16.jar"))
  9.     testImplementation(libs.junit)
  10.     androidTestImplementation(libs.ext.junit)
  11.     androidTestImplementation(libs.espresso.core)
  12. }
复制代码
5.报错:3 files found with path ‘META-INF/DEPENDENCIES’ ...
   3 files found with path 'META-INF/DEPENDENCIES'.
Adding a packaging block may help, please refer to
https://developer.android.com/reference/tools/gradle-api/8.3/com/android/build/api/dsl/Packaging
for more information
  


解决办法:在build.gradle(Module:app)的android字段内里,加上这段代码,排除掉冲突的体系依靠包即可:
  1. packaging {
  2.         resources.excludes.add("META-INF/DEPENDENCIES");
  3.         resources.excludes.add("META-INF/NOTICE");
  4.         resources.excludes.add("META-INF/LICENSE");
  5.         resources.excludes.add("META-INF/LICENSE.txt");
  6.         resources.excludes.add("META-INF/NOTICE.txt");
  7.     }
复制代码
六、摆设假造机

到这里,项目摆设完成了,我们再次点击Make Module 这个小锤子,终于没有出现报错信息了。

接下来:我们开始摆设假造机,依次点击:1->2->3.


在这个页面,任意选择一个机型:

下一步,选择API,这里你们可以试一下 35/34,我的电脑不知道什么缘故原由选择这两个都会出现冷启动失败,而网上的解决办法我都举行了尝试,无疑都失败了,末了,我尝试使用了低API,如API 24,发现没有报错。

七、项目展示

末了,点击运行,运行成功!


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

渣渣兔

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表