【问题标题】:Android Studio Wear Os application can't be installed INSTALL_PARSE_FAILED_NO_CERTIFICATES无法安装 Android Studio Wear Os 应用程序 INSTALL_PARSE_FAILED_NO_CERTIFICATES
【发布时间】:2020-10-25 15:59:04
【问题描述】:

我是 Android Studio 魔法世界的新手。我正在尝试开发一个简单的 Wear Os 应用程序来扫描附近的蓝牙设备。

MainActivity.java

package com.firstapp.testble;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends WearableActivity {

    private ListView listView;
    private ArrayList<String> mDeviceList = new ArrayList<String>();
    private BluetoothAdapter mBluetoothAdapter;

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

        listView = (ListView) findViewById(R.id.listView);

        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if(mBluetoothAdapter == null){
            System.out.println(">>>>>>>>>>>>>>>>>>ERRORRE");
        }else{
            mBluetoothAdapter.startDiscovery();

            IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(mReceiver, filter);

            // Enables Always-on
            setAmbientEnabled();
        }
    }


    @Override
    protected void onDestroy() {
        unregisterReceiver(mReceiver);
        super.onDestroy();
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                BluetoothDevice device = intent
                        .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                mDeviceList.add(device.getName() + "\n" + device.getAddress());
                Log.i("BT", device.getName() + "\n" + device.getAddress());
                listView.setAdapter(new ArrayAdapter<String>(context,
                        android.R.layout.simple_list_item_1, mDeviceList));
            }
        }
    };
}

AndroidManifest.xml

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

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

    <uses-feature android:name="android.hardware.type.watch" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault">
        <uses-library
            android:name="com.google.android.wearable"
            android:required="true" />

        <!--
               Set to true if your app is Standalone, that is, it does not require the handheld
               app to run.
        -->
        <meta-data
            android:name="com.google.android.wearable.standalone"
            android:value="true" />

        <activity
            android:name=".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>

当我尝试在我的 Fossil SmartWatch 中调试应用程序并将 APK 上传到设备时,我收到以下错误:

Launching 'app' on Physical Device.
Timed out waiting for process (com.firstapp.testble) to appear on fossil-garrett_hr-127.0.0.1:4444.
Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_NO_CERTIFICATES

List of apks:
[0] 'C:\Users\marac\AndroidStudioProjects\TestBLE\app\build\outputs\apk\debug\app-debug.apk'
APK signature verification failed.

对于其他简单的应用程序,我没有这种问题。 这是我已经尝试过的:

  1. Build> 生成 Singned Bundle / APK
  2. 清理项目和重建项目
  3. 文件 > 使缓存无效/重新启动
  4. 断开并重新连接智能手表
  5. 重新安装 Android Studio

我不明白为什么我会遇到这个问题以及为什么我只在这个项目中遇到这个问题。你能帮我解决吗?

谢谢, 马拉

【问题讨论】:

  • 您解决了吗?在调试模式下运行时,我似乎能够通过 USB 部署到我的手机。我以前可以通过 wifi 和 wearos 做同样的事情,但现在遇到了同样的错误。
  • BroadcastReceiver is not support in WearOS 我已经使用本教程解决了:medium.com/@martijn.van.welie/…

标签: java android-studio wear-os android-bluetooth bluetooth-gatt


【解决方案1】:

如果您已经签署了您的 apk,您可能会考虑安装发布版本而不是您尝试安装的调试版本。

从以下日志中,我可以看到您正在尝试安装调试版本。

[0] 'C:\Users\marac\AndroidStudioProjects\TestBLE\app\build\outputs\apk\debug\app-debug.apk'

发行版apk可以在\Users\marac\AndroidStudioProjects\TestBLE\app\build\outputs\apk\release文件夹下找到。

【讨论】:

  • 问题是我需要在调试模式下测试我的应用程序。我试图使 Build> Generate Singned Bundle / APK butnothig 的操作有效。代码编译正确,问题仅在于我尝试将 apk 上传到我的 SmartWatch 时。有什么我不明白的吗?
  • 我明白了。你能检查一下这个答案吗? stackoverflow.com/a/62157265/3145960
  • 您解决了吗?我的 gradle 中没有任何签名配置。
猜你喜欢
  • 2020-02-27
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多