Slow Gradle Download Speed
To speed up Gradle downloads, modify the distributionUrl in the project's gradle/wrapper/gradle-wrapper.properties file to use a domestic mirror:
distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-7.5-bin.zip
Failed to Resolve Classpath Dependencies
The error Could not resolve all files for configuration ':classpath' typically occurs due to misconfigured repositories. Ensure that Google and Maven Central repositories are correctly added to your project's build.gradle (project-level) or settings.gradle file. If issues persist, verify dependency versions against the official Android developer documentation or clear Gradle caches via File > Sync Project with Gradle Files.
Slow Android SDK Download
Accelerate SDK downloads by configuring domestic mirrors (e.g., Alibaba, Tencent) in Android Studio's SDK Manager:
- Open
Settings > Appearance & Behavior > System Settings > Android SDK - Navigate to
SDK Update Sitesand add miror URLs for SDK components Alternatively, manually download the SDK package from official mirror sites and place it in your SDK installation directory.
Slow Code Hints in Android Studio
To fix laggy Kotlin/Java code completion:
- Increase IDE memory allocation in
idea64.exe.vmoptions(locate viaHelp > Edit Custom VM Options) - Disable unused plugins (
Settings > Plugins) - Enable offline mode when working without an internet connection
- Update Android Studio to the latest stable version
Missing Layout ID Declaration Error
When seeing the red error @layout/activity_main does not contain a declaration with id [target_id], use the following fix:
- Press
Alt + Enteron the error line - Select the option to Suppress MissingInflatedId with an annotation to resolve the false positive, or double-check that the target ID exists in the corresponding layout XML file.
Cannot Modify Button Background Color
If you can't change a Button's background color in Android Studio, adjust your app's theme configuration:
- Open
res/values/themes.xml - Modify the theme parent value from:
<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
to:
<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
Activity Class Not Found Error
Resolve the Activity class {com.example/com.example.MainActivity} does not exist error by:
- Cleaning and rebuilding the project (
Build > Clean ProjectthenBuild > Rebuild Project) - Verifying the Activity is correctly declared in
AndroidManifest.xml - Invalidating caches and restarting Android Studio (
File > Invalidate Caches... > Invalidate and Restart)
Code Changes Not Reflecting After Run
If your modified code doesn't appear in the running app, try these fixes:
- Invalidate caches and restart Android Studio
- Disable Instant Run (for older Android Studio versions)
- Ensure the correct build variant is selected in the toolbar
Build Failure Due to Non-ASCII Project Path
The error indicating non-ASCII characters in the project path can be fixed by:
- Moving the project to a directory with only English characters and numbers
- Or adding the following line to the project's
gradle.propertiesfile to bypass the check:
android.overridePathCheck=true
AVD Already Running Error
When encountering Error while waiting for device: Nexus 6 API 34 is already running (even if it's not), navigate to C:\Users\<YourUsername>\.android\avd\Nexus_6_API_34.avd and delete all .lock files, then restart the emulator.
Repository Conflict for Third-Party Dependencies
If you see Build was configured to prefer settings repositories over project repositories when adding dependencies like Glide:
- Ensure Google and Maven Central are declared in
settings.gradle:
repositories {
google()
mavenCentral()
}
- Add the dependency only in the app-level
build.gradle:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.16.0'
}
Glide SecurityException: Missing Internet Permission
The error java.lang.SecurityException: Permission denied (missing INTERNET permission?) occurs when Glide tries to load remote images without internet access. Add the following permission to AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
WebView JavaScript Alert Not Displaying
If webView.loadUrl("javascript:alert('hello')") doesn't work, enable JavaScript in WebView settings first:
webView.settings.javaScriptEnabled = true
webView.loadUrl("javascript:alert('hello')")
Ensure the WebView is fully initialized before executing JavaScript code.
Toast.setGravity() Not Working on Android 11+
On Android 11 (API 30) and above, setGravity() has no effect on default text Toasts (you'll see the warning setGravity() shouldn't be called on text toasts). To adjust the position, create a custom Toast layout or use a Snackbar as an alternative.
AlertDialog Import and Compatibility Issues
If you can't find AlertDialog, use the AndroidX library import for better compatibility:
import androidx.appcompat.app.AlertDialog
val builder = AlertDialog.Builder(this)
Avoid the deprecated android.app.Fragment; use androidx.fragment.app.Fragment instead.
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED Error
This error stems from invalid entries in AndroidManifest.xml. For example, if the error mentions an invalid taskAffinity value, ensure the attribute contains at least one '.' separator (e.g., com.example.myapp.task instead of myapptask). Double-check all component declarations for typos or formatting isues.
New vs. Deprecated Fragment APIs
Use the AndroidX Fragment library for modern Android development:
// Recommended (AndroidX)
import androidx.fragment.app.Fragment
class MyFragment : Fragment() {
// Fragment implementation
}
// Fragment transaction
supportFragmentManager.beginTransaction()
.replace(R.id.fl_container, MyFragment())
.commit()
Avoid the deprecated framework Fragment:
// Deprecated
import android.app.Fragment
class OldFragment : Fragment() {
// Deprecated implementation
}
False Positive Missing Layout ID Error
If the error @layout/activity_event does not contain a declaration with id btn_event disappears after a while, it's a cache-related false positive. You can suppress it with the annotation:
@SuppressLint("MissingInflatedId")
Or sync the project with Gradle files to resolve the issue.
External Storage Permission Error
For FileNotFoundException: /storage/emulated/0/... (Permission denied) when accessing external files:
- Add the permission to
AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- For Android 6.0 (API 23+) and above, request runtime permissions before accessing storage:
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
1
)