失败[INSTALL_PARSE_FAILED_MANIFEST_MALFORMED] Android

时间:2015-05-20 22:11:32

标签: android android-manifest

我已经找到了答案的每个地方。我已经为这个错误找到了许多解决方案,但它对我不起作用。我3天前刚刚开始使用android。它一直很好,直到今天。我收到此错误

Installing com.mycompany.myfirstapp
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.mycompany.myfirstapp"
pkg: /data/local/tmp/com.mycompany.myfirstapp
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]

我见过的解决方案是关于包装标签/名称中的国会大厦字母。我没有国会大厦的信,但我仍然得到错误。 这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.mycompany.myfirstapp">
        <uses-sdk android:minSdkVersion="7"  android:targetSdkVersion="18" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MyActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".DisplayMessageActivity"
                android:label="@string/title_activity_display_message"
                android:parentActivityName=".MyActivity" >
                <meta-data
                    android:name="android.support.PARENT_ACTIVITY" />
            </activity>
        </application>
    </manifest>

我不确定发生了什么。拜托,我真的很想学。

更新

package com.mycompany.myfirstapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;



public class MyActivity extends AppCompatActivity {

    public final static String EXTRA_MESSAGE = "com.mycompany.myfirstapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_my, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:orientation="horizontal">
    <EditText android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />
</LinearLayout>

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MyActivity">
    <item android:id="@+id/action_settings" android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="never" />
    <item android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        app:showAsAction="ifRoom" />
</menu>

<resources>
    <string name="app_name">My First App</string>


    <string name="action_settings">Settings</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="title_activity_display_message">My Message</string>
    <string name="action_search">Search</string>
    <string name="hello_world">Hello world!</string>

</resources>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.mycompany.myfirstapp.DisplayMessageActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

package com.mycompany.myfirstapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class DisplayMessageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);
        setContentView(textView);
        }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

这是整个项目。非常感谢你们的帮助。

LogCat文件

05-21 08:49:15.171      181-181/? E/﹕ invalid crash request of size 4 (from pid=16717 uid=0)
05-21 08:49:15.287      541-559/? W/qcom_sensors_hal﹕ hal_sensor1_data_cb: SENSOR1_MSG_TYPE_BROKEN_PIPE
05-21 08:49:15.295  16808-16808/? E/Diag_Lib﹕ Diag_LSM_Init: Failed to open handle to diag driver, error = 2
05-21 08:49:15.295  16808-16808/? E/Sensors﹕ sns_fsa_la.c(386):fsa: fflush failed, 9
05-21 08:49:15.295  16808-16808/? E/Sensors﹕ sns_fsa_la.c(386):fsa: fflush failed, 9
05-21 08:49:15.324  16808-16810/? W/Sensors﹕ sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b70079d0
05-21 08:49:15.383  16808-16812/? W/Sensors﹕ sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
05-21 08:49:15.396  16808-16814/? E/Sensors﹕ sns_debug_main.c(565):Debug Config File missing in EFS!
05-21 08:49:21.758     541-3523/? D/WifiService﹕ acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@e56ac47}
05-21 08:49:21.778     541-2402/? D/WifiService﹕ releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@e56ac47}

1 个答案:

答案 0 :(得分:3)

<meta-data
    android:name="android.support.PARENT_ACTIVITY" />

meta-data元素始终需要android:valueandroid:resource属性。

完全删除此元素,或向元素添加值,例如:

<meta-data
    android:name="android.support.PARENT_ACTIVITY"
    android:value=".MyActivity"/>

PARENT_ACTIVITY元数据有助于ancestral navigation。)