简体   繁体   中英

How to run Android app correctly with AVD?

I am trying to run my first android app. I follow tutorial 'My first App' on developer.android.com.

activity_main.xml is simple:

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <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:hint="@string/send_button" />

</LinearLayout>

MainActivity.java is as default.

The problem is that when I run my Andoid app it does open new virtual device but with black screen and a few buttons on the right pane. So there is nothing displayed from my activity_main.xml.

In console I see such output:

[2014-02-11 14:21:20 - MyFirstApp] ------------------------------
[2014-02-11 14:21:20 - MyFirstApp] Android Launch!
[2014-02-11 14:21:20 - MyFirstApp] adb is running normally.
[2014-02-11 14:21:20 - MyFirstApp] Performing com.example.myfirstapp.MainActivity activity launch
[2014-02-11 14:21:20 - MyFirstApp] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2014-02-11 14:21:34 - MyFirstApp] Launching a new emulator with Virtual Device 'MyVirtualDevice'
[2014-02-11 14:22:17 - MyFirstApp] emulator-5554 disconnected! Cancelling 'com.example.myfirstapp.MainActivity activity launch'!
[2014-02-11 14:22:54 - Emulator] Failed to create Context 0x3005
[2014-02-11 14:22:54 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2014-02-11 14:22:54 - Emulator] WARNING: Data partition already in use. Changes will not persist!
[2014-02-11 14:22:54 - Emulator] WARNING: SD Card image already in use: C:\Users\Vova\.android\avd\MyVirtualDevice.avd/sdcard.img
[2014-02-11 14:22:54 - Emulator] WARNING: Cache partition already in use. Changes will not persist!
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:55 - Emulator] emulator: warning: opening audio input failed
[2014-02-11 14:22:55 - Emulator] 
[2014-02-11 14:22:56 - MyFirstApp] New emulator found: emulator-5556
[2014-02-11 14:22:56 - MyFirstApp] Waiting for HOME ('android.process.acore') to be launched...
[2014-02-11 14:23:08 - MyFirstApp] emulator-5556 disconnected! Cancelling 'com.example.myfirstapp.MainActivity activity launch'!

My AndroidManifest.xml is :

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

What can be wrong?

Thank you!

Welcome to the world of Android development. There's a few things here:

  1. The emulator is complaining that you're trying to start a new one while one using that image is already running. Selecting the existing (running) emulator when launching.
  2. Check to make sure the API level you are running on your emulator matches what's in your manifest (level 18)
  3. I would highly recommend using Genymotion - it's a much (much!!) faster emulator

It seems to be a problem with your IDE, not your code. The console often states that the device disconnected and it therefore cancelled your program.
It would help, if we'd know what IDE you're working in. Android Studio, Eclipse or another?
Then someone probably could give you more specific advice how to solve the problem with the AVD, if you can't figure it out yourself. ;)

您是否有api 18的sdk ?。因为您已在manifest。中设置了此代码。请尝试将目标版本设置为已安装的目标版本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM