【问题标题】:What's the difference between Android Studio install and "adb install"Android Studio 安装和“adb 安装”有什么区别
【发布时间】:2015-01-04 17:45:25
【问题描述】:

当我从 Android Studio 安装我的应用程序时,它运行良好,但是当我使用 adb install <pc path to apk>adb shell pm install -r <device path to apk> 安装它时,应用程序无法将文件写入设备文件系统......

有人知道为什么吗?有什么不同?使用 adb 安装不会赋予应用所需的权限吗?

谢谢!

编辑:

try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element root = doc.createElement("map");
        doc.appendChild(root);
        buildCamCapabilitiesXML(cm.getCameraCharacteristics(cameraID), doc, root);
        writeXMLToFile(doc);
        renameFileAndDeleteOldOne(storagePath + fileName, new File(storagePath + fileName + FILE_TEMP_EXTENSION));
    } catch (CameraAccessException e) {
        e.printStackTrace();
        Log.e(TAG, "Failed to access camera to get camera abilities");
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        Log.e(TAG, "Failed to get a DocumentBuilder");
    } catch (TransformerException e) {
        e.printStackTrace();
        Log.e(TAG, "Failed to write capabilities xml file to filesystem");
    }

private void writeXMLToFile(Document doc) throws TransformerException {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        transformer.transform(new DOMSource(doc), new StreamResult(new File(storagePath + fileName + FILE_TEMP_EXTENSION)));
    }

【问题讨论】:

  • 由于 Android Studio 使用 ADB 安装应用,所以没有区别。您是什么意思“应用程序无法将文件写入设备文件系统”?我们需要更多细节。
  • 没有错误或者只是没有写入它应该写入的文件。我有一个脚本等待应用程序应该创建的文件,并且由于应用程序没有写入文件,因此脚本只是进入无限循环。
  • 有一个错误,你只是不知道如何正确使用try..catch。请出示相关代码。
  • 检查我的编辑。 logcat中没有错误。同样,没有任何更改的同一个应用程序在我使用 adb 安装时无法运行,但在我使用 Android Studio 安装时运行良好。
  • 在这两种情况下,您可能安装了不同的构建版本 - IDE 安装的文件可能与您想象的不同

标签: android android-studio adb


【解决方案1】:

解决了。

显然,该应用必须在由 adb 安装后从设备上启动一次(这在 Android Studio 中自动完成)。

之后它就完美运行了,但不知道为什么......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-30
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2011-04-22
    • 2020-04-03
    • 2021-09-08
    相关资源
    最近更新 更多