问题
When I create a new project in Android Studio 3.3, it shows an error at Run -> Edit Configurations
saying
default activity is not found.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
This is my activity_main.xml file. It shows an error in line
tools:context=".MainActivity"
saying
Unresolved Class MainActivity
Here is my AndroidManifest.xml file - everything seems to be all right here -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
The files colors.xml , ic_launcher_background.xml, and ic_launcher_foreground.xml are not correctly formed, and look something like this -
f
isInitialized
kotlin
Boolean
reflect
KProperty0
SinceKotlin
version
1.2
internal
InlineOnly0
4" 8�H PX�� (� �
I tried to Clean and Rebuild
project, which gave an error saying
colors.xml is not formed properly.
I tried File -> Invalidate Caches/Restart
, but it still shows the same error.
This problem started one day after updating Android Studio 3.2.1
to Android Studio 3.3
. It worked all fine the first day, but when I tried run an app on the second day, it started showing this error saying Default Activity not found
.
Is there any way to fix this issue and continue using Android Studio version 3.3?
EDIT -
Yay! As @Andreas suggested, my Android Studio itself could've been corrupted, and works all right after uninstalling and reinstalling the same version (I did not even revert to an older version). Should check if this problem might repeat again in a few days.
回答1:
Close the project and Delete Cache
folder inside your C:\Users\UserName\.AndroidStudio3.3
folder and Build your project.
回答2:
There is a chance that Android Studio itself could've been corrupted. Uninstalling and Reinstalling Android Studio solves the problem.
回答3:
I had the same problem with version 3.4. Goto Build -> Edit Build Types -> SDK location and checked Use embedded JDK (recommended). It worked fine.
回答4:
Restart your android studio with option Invalidate Caches/Restart. You can find this option under file option. I think it will work for you.
回答5:
In Android Studio 3.5.2 my custom launcher/custom home app is getting this error. I was able to reproduce it by creating a brand new blank activity app, then replacing
<category android:name="android.intent.category.LAUNCHER"/>
with
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
in the manifest. That single change causes Android Studio to lose track of the default activity. I'm able to continue debugging by specifying the activity in the Run/Debug configurations.
来源:https://stackoverflow.com/questions/54319860/default-activity-not-found-bug-in-android-studio-3-3