0

I tried to build and run from the following sample but I'm getting couple errors:

1- Error running MainActivity: The activity 'MainActivity' is not declared in AndroidManifest.xml
2- Error:(553, 69) String types not allowed (at 'activity_horizontal_margin' with value '').
3- Error:Execution failed for task ':app:processDebugResources'.> com.android.ide.common.process.ProcessException: Failed to execute aapt

Can somebody tell me what I'm missing?

rene
  • 41,474
  • 78
  • 114
  • 152
  • Every activity should be declared in AndroidManifest file https://stackoverflow.com/questions/19122386/activity-declaration-in-androidmanifest-xml – dzikovskyy Jul 19 '17 at 17:38
  • Possible duplicate of [Activity Declaration in AndroidManifest.xml](https://stackoverflow.com/questions/19122386/activity-declaration-in-androidmanifest-xml) – dzikovskyy Jul 19 '17 at 17:41
  • I read that page before asking my question and read couple other pages and tested their suggestion. But still not working. –  Jul 19 '17 at 17:43

2 Answers2

0

The first error ("The activity 'MainActivity' is not declared in AndroidManifest.xml") means exactly what it says. There is a file in your project named AndroidManifest.xml and you must declare all Activitys in this file. Here's the manifest created by Android Studio for a new project:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.test.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"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Two important things to note:

1) The package attribute of the <manifest> tag (on line 3 in this example) must match the package name you're using for your Java code.

2) There must be an <activity> tag for your MainActivity (see line 12 in the example).

The second error ("String types not allowed (at 'activity_horizontal_margin')") is harder to debug without your code, but here's a guess. The page you linked two includes these two lines:

android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin"

You have to make sure (a) that you did not remove the @dimen/ prefix from these, and (b) that you have declared a dimen resource with the name activity_horizontal_margin. Usually that would be done by creating res/values/dimens.xml with content something like:

<resources>
    <dimen name="activity_horizontal_margin">16dp</dimen>
</resources>

You could also replace these dimen resource references with in-place values, like this:

android:paddingLeft="16dp" 
android:paddingRight="16dp"
Ben P.
  • 52,661
  • 6
  • 95
  • 123
  • Thank you so much for detail information. I'm testing it right now and hopefully it will fix it. –  Jul 19 '17 at 17:53
0

1- Error running MainActivity: The activity 'MainActivity' is not declared in AndroidManifest.xml

Every Android app needs an manifests/AndroidManifest.xml. It contains general information about the app, like the app's name, icon and (what's causing the error) a list of all activities used in the app. In this files "application" tag you need to insert this:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
 </activity>

This declares the activity "MainActivity" as the activity to start, when launching the app.

2- Error:(553, 69) String types not allowed (at 'activity_horizontal_margin' with value '').

As Ben P. mentioned the Main.xml from the guide refers to a dimen resource named activity_horizontal_margin. To adress this error you either have to declare it in the res/values/dimens.xml file, or replace that code by some explicit values.

3- Error:Execution failed for task ':app:processDebugResources'.> com.android.ide.common.process.ProcessException: Failed to execute aapt

This error could occur, just because it couldn't find the requiered resources (like in error 2). The same error occured here already, because of another missing resource. So fixing the other 2 issues should adress this error too.

vstollen
  • 151
  • 1
  • 11