简体   繁体   中英

error "bad component name" when launching android app with adb shell am start

I'm trying to launch an activity with adb shell am but i always had the error Bad component name.

 C:\Users\EnzoAbjean\Documents\Automatisation\TelinkSH-Enzo\qa-automatisation-tool>adb -s "R5CRC0HRRAW" shell am start -n com.telink.ble.mesh.ui.DeviceProvisionActivity

Exception occurred while executing 'start':
java.lang.IllegalArgumentException: Bad component name: com.telink.ble.mesh.ui.DeviceProvisionActivity

And this is my Manifest:

 <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         package="com.telink.ble.mesh.demo">
      <application
             android:name="com.telink.ble.mesh.LightingApplication"
            android:allowBackup="true"
             android:icon="@mipmap/ic_launcher"
             android:label="@string/app_name"
             android:requestLegacyExternalStorage="true"
             android:supportsRtl="true"
             android:theme="@style/AppTheme"
             tools:ignore="GoogleAppIndexingWarning">
       <activity
                android:name="com.telink.ble.mesh.ui.DeviceProvisionActivity"
                 android:screenOrientation="portrait"
                 android:windowSoftInputMode="stateAlwaysHidden"
                 tools:ignore="LockedOrientationActivity" />
 

I don't really know how it doesn't worked. I tried to put the package name "com.telink.ble.mesh.demo" before but nothing.

Add exported and intent filter:

   <activity
            android:name="com.telink.ble.mesh.ui.DeviceProvisionActivity"
             android:screenOrientation="portrait"
             android:windowSoftInputMode="stateAlwaysHidden"
             tools:ignore="LockedOrientationActivity"
             android:exported="true">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>

    </activity>
             

then you should be able to launch with

am start -n com.telink.ble.mesh.demo/com.telink.ble.mesh.ui.DeviceProvisionActivity

as @Robert mentioned in the comments.

android {
compileSdkVersion 29
buildToolsVersion = '28.0.3'

defaultConfig {
    applicationId "com.telink.ble.smart.home"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 3
    versionName "1.0.2"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Now my command line is adb -s "R5CRC0HRRAW" shell am start -n com.telink.ble.smart.home/com.telink.ble.mesh.ui.DeviceProvisionActivity

I looked my build.gradle and found a new path in the defaultConfig: "com.telink.ble.smart.home" and and tried this path its work. In my manifest i had to add an export for my activity. Thanks for your answers @Robert and @Diego Torres Milano.

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