1. Gradle configuration
We often encounter imported projects that fail to compile. In many cases, problems arise because of different configurations. There are two main configurations:
Android Gradle Plugin Version
Gradle Version
Find a project that can run normally and configure the two to be the same, which will usually solve the problem.
① Android Gradle Plugin Version modification
Modify dependencies in build.gradle in the project root directoryas follows
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
}
}
② Gradle Version View and modify
Flie —> Project Struture —> Gradle VersionRevise
2. JDK configuration
Sometimes you will encounter problems with JDK version incompatibility, and you need to install the corresponding JDK locally.
Flie —> Project Struture —> SDK Location —> Gradle Settings
Gradle JDK Select the corresponding JDK from the drop-down list
3. How to modify the project name
① Close this project
② Find the folder where the project is located and change the file name to the name you need
③ settings.gradle rootProject.name = “xxx” Change it to the name you need
④ Re-import and open this project in as.
4. Change the package name
① Do not change the package level
- Open your project in Android Studio.
- Right-click the app directory, select 'Refactory', and then select 'Rename'.
- In the pop-up dialog box, change the original package name to the new package name. For example, if the original package name was com.example.app, it is now com.newname.app.
- Confirm the name change and wait for Android Studio to update the package name references in all files. This may take some time, so be patient.
AndroidManifest.xmlThe package name will normally be modified along with it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="crazy.floatwindow">
applicationId modification
Build.gradle in the app directory is modified as follows
plugins {
id 'com.android.application'
}
android {
defaultConfig {
applicationId "crazy.floatwindow"
}
}
② Change folder hierarchy
The general idea is to create a new package hierarchy, move the corresponding files there, and then check the package names of AndroidManifest.xml and build.gradle. If they have not been changed, change them manually. If they are synchronized, ignore them. Recompile and generate the APK to see if there is an error in resource reference, search and replace globally.