简体   繁体   English

Android Automotive:无法识别启动活动:未找到默认活动

[英]Android Automotive: Could not identify launch activity: Default Activity not found

I have just created my first Android Automotive project:我刚刚创建了我的第一个 Android Automotive 项目:

图片

when I run AndroidAutoDemo.mobile module it works fine:当我运行AndroidAutoDemo.mobile模块时,它工作正常:

在职的

Unfortunately when I switch to AndroidAutoDemo.automotive module I get:不幸的是,当我切换到AndroidAutoDemo.automotive模块时,我得到:

Could not identify launch activity: Default Activity not found Error while Launching activity Failed to launch an application on all devices无法识别启动活动:未找到默认活动启动活动时出错无法在所有设备上启动应用程序

This is the Android Manifest file in AndroidAutoDemo.automotive module (left as default):这是AndroidAutoDemo.automotive模块中的 Android Manifest 文件(默认保留):

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

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:appCategory="audio"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidAutoDemo" />

</manifest>

This is my mobile emulator:这是我的移动模拟器:

模拟器

  • How can I fix?我该如何解决?

Each Manifest file should include information about available activities and launcher activity.每个清单文件应包含有关可用活动和启动器活动的信息。 Launcher activity needs to be defined with some additional Intent filters, for example:启动器活动需要使用一些额外的 Intent 过滤器来定义,例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.car">

<uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
    <activity android:name="com.example.car.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

To run automotive app you need Automotive emulator and Automotive flavor with Manifest like below.要运行汽车应用程序,您需要汽车模拟器和带有 Manifest 的汽车风格,如下所示。 Also there is no Automotive emulator provided by Google yet but you can get other open source emulator from like Polestar https://developer.polestar.com/sdk/polestar2-sys-img.xml and Volvo https://developer.volvocars.com/sdk/volvo-sys-img.xml You don't have to add new activity谷歌还没有提供汽车模拟器,但您可以从 Polestar https://developer.polestar.com/sdk/polestar2-sys-img.xml和沃尔沃https://developer.volvocars 等获得其他开源模拟器。 com/sdk/volvo-sys-img.xml您不必添加新活动

if want to understand you can go through example source code https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app-samples/helloworld/如果想了解您可以通过示例源代码https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app-samples/helloworld/

` `

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="androidx.car.app.sample.helloworld"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- Various required feature settings for an automotive app. -->
    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />
    <uses-feature
        android:name="android.software.car.templates_host"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.wifi"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.screen.portrait"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.screen.landscape"
        android:required="false" />

    <application
      android:label="@string/app_name"
      android:icon="@drawable/ic_launcher"
      android:extractNativeLibs="false">

        <meta-data
            android:name="com.android.automotive"
            android:resource="@xml/automotive_app_desc"
            tools:ignore="MetadataTagInsideApplicationTag" />

        <meta-data android:name="androidx.car.app.minCarApiLevel"
            android:value="1"
            tools:ignore="MetadataTagInsideApplicationTag" />

        <service
            android:name="androidx.car.app.sample.helloworld.common.HelloWorldService"
            android:exported="true">
          <intent-filter>
            <action android:name="androidx.car.app.CarAppService" />
          </intent-filter>
        </service>

        <activity
            android:name="androidx.car.app.activity.CarAppActivity"
            android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
            android:exported="true"
            android:launchMode="singleTask"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="distractionOptimized" android:value="true"/>
        </activity>
    </application>
</manifest>

` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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