1

The problem occurred overnight. One day, everything worked fine. I shut my computer down and started it back up on another day. However, without changing a thing, I tried to launch my App on the same virtual device I had before and somehow it wont launch because:

"Error running 'app'. Default Activity not found."

My manifest looks like this. I changed the package name and the two activities below (see comments below). The rest is exactly the same.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MyPackageName">

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />

<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=".LoginActivity"
        android:label="@string/title_activity_login"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".AnotherActivity" />
    <activity android:name=".OneMoreActivity">
    </activity>

    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="364e8b3f6acfddf9ad32bed8c1503bb762b19cd5" />


</application>

</manifest>

And normally my app would just start with the Login Activity. However, now it does not. I tried to "Invalidate Caches / Restart". Nothing changed. I restarted AS multiple times. Still, nothing.

Then I tried to change the Launch Options. Current Option was set to "Default Activity". So I tried to change it to a specific one. Namely, the LoginActivity. But then it tells me:

"Error running 'app'. The Activity 'LoginActivity' is not declared in AndroidManifest.xml."

It tells me it's not declared, which it clearly is. Otherwise I wouldn't be able to choose it from the dropdown in the first place. I also tried to start on another Activity. "MainActivity". Still nothing.

What exactly am I doing wrong? Is there maybe a workaround where I can manually get the APK on my virtual device so that I can at least keep working?

Edit

I already tried deleting the .gradle-folder. Sadly this didn't work. I tried pushing it to git and cloning it again in another folder. That didn't work either.

Workaround

So far I've only been able to find a workaround:

  • Go to Run/Edit Configurations...
  • Go to General/Launch Options -> Launch: Nothing
  • Run as you normally would. Android Studio will build the project and install the application to your device, but won't launch it!
  • Launch your app manually on your device.
  • Go to Run/Attach Debugger to Android Process.
  • Choose your app.

Obviously, that's a little bit of a hassle and might make debugging the start of an app more difficult. So I'm still looking for an actual solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46
  • Delete .gradle file and invalidate and restart android studio should solve your problem – Aman Rawat Dec 28 '18 at 12:05
  • I have same problem, I fix this problem by create new project and copy/pate your code into new one otherwise post on 'GitHub' clone to different machine – Rahul Chokshi Dec 28 '18 at 12:05
  • @Smogen can you share the entire manifest file, might be beneficial – Nero Dec 28 '18 at 12:42
  • @Nero I added the manifest. As I said, the only change I made before posting is renaming the package to "MyPackageName" and the two activities "AnotherActivity" and "OneMoreActivity". The others have the correct names. – Benjamin Basmaci Dec 29 '18 at 16:00
  • @Smogen please also share the entire code for the Login activity (from top which also includes your imports) – Nero Dec 29 '18 at 17:26

1 Answers1

0

I've found the answer when I tried to look for a solution to another problem that randomly popped up out of nowhere.

Androidstudio wouldnt load any previews and put warnings in my layouts, because

One or more layouts are missing the layout_width or layout_height attributes.

One solution suggested in the answer I found for that problem was to delete all files in

C:\Users\UserName.AndroidStudio3.2\system\caches

Thats what I did and it solved both problems. Guess the developers have some fixing to do.

Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46