【问题标题】:Modify AndroidManifest.xml through Shoutem platform通过 Shoutem 平台修改 AndroidManifest.xml
【发布时间】:2017-05-03 13:34:17
【问题描述】:

在这种情况下,我想添加/修改 AndroidManifest.xml 以获得权​​限 (FINE_LOCATION),所以我查看了它在 Shoutem firebase 扩展 (https://github.com/shoutem/extensions/tree/master/shoutem-firebase) 中是如何完成的。

在预览应用程序中,这不是必需的,该应用程序已经获得了位置(以及更多)权限,但我认为如果我想将其提交到 Play 商店/手动安装,应该将其添加到我的自定义扩展程序中它在我的 Android 设备上(如果我猜错了,请纠正我)。

问题

我是否完成了使用 Shoutem 平台修改 AndroidManifest.xml 的正确步骤?

结果

使用 Shoutem CLI 构建成功,但 CLI 在复制到构建文件夹时挂起,在 Android 设备上安装失败

我做了以下事情: - 在 /app 中创建了一个 AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.shoutemapp">
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application>
    </application>
</manifest>

更新 app/package.json,添加:

,
"rnpm": {
    "commands": {
        "postlink": "node node_modules/[myusername].[extensionname]/scripts/run.js"
    }
}

/scripts/run.js 的内容:

require('./android/copy_custom_manifest');

/android/copy_custom_manifest 的内容:

与 firebase 扩展相同,我的 username.extensionname 在 extensionPath 中:

/* eslint-disable max-len*/
 'use_strict';

const fs = require('fs');
const MANIFEST_FILE = 'AndroidManifest.xml';

const extensionPath = './node_modules/[myusername].[extensionname]';
const manifestFilePath = `${extensionPath}/${MANIFEST_FILE}`;
const customManifestFileDestination = `android/app/src/customized/${MANIFEST_FILE}`;

const readStream = fs.createReadStream(manifestFilePath);
const writeStream = fs.createWriteStream(customManifestFileDestination, { flags: 'a' });
readStream.on('error', console.log.bind(null, `Unable to read from ${manifestFilePath}`));
writeStream.on('error', console.log.bind(null, `Unable to write to ${customManifestFileDestination}`));
writeStream.on('finish', console.log.bind(null, `copied ${manifestFilePath} to ${customManifestFileDestination}`));

fs.truncate(customManifestFileDestination, 0, (err) => {
  if (err) {
    process.exitCode = 1;
    throw new Error(`Unable to overwrite, ${manifestFilePath} does not exist`);
  }

  console.log(`Overwrite ${customManifestFileDestination} with ${manifestFilePath}`);
  readStream.pipe(writeStream);
});

我在构建过程中没有遇到错误,但应用程序不会安装在物理设备上,使用:

shoutem build-android

控制台输出:

BUILD SUCCESSFUL
Total time: 2 mins 43.478 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Copying .apk to /Users/matthijs/Documents/shoutem/builds
--> It stops on this last line (copying .apk), no error.
There was one error however:
[5/3/2017, 12:06:07 PM] <START> Initializing Packager
[5/3/2017, 12:06:07 PM] <START> Building in-memory fs for JavaScript
[5/3/2017, 12:06:07 PM] <END> Building in-memory fs for JavaScript (108ms)
[5/3/2017, 12:06:07 PM] <START> Building Haste Map
[5/3/2017, 12:06:07 PM] <END> Building Haste Map (304ms)
[5/3/2017, 12:06:07 PM] <END> Initializing Packager (473ms)
platform.buildPlatform(...).finally is not a function
If you think this error is caused by bug in the shoutem command, you can report the issue here: https://github.com/shoutem/cli/issues
Make sure to include the information printed using the `shoutem last-error` command
> @shoutem/mobile-app@0.56.0 build /private/var/folders/xp/strzbzt15zz4k1pvmgc99rj40000gn/T/tmp-8209NeOBTGdT1e1B
> node scripts/build "--platform" "android" "--outputDirectory" "/Users/matthijs/Documents/shoutem/builds"
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preCustomizedReleaseBuild UP-TO-DATE

【问题讨论】:

    标签: android react-native shoutem


    【解决方案1】:

    这是@shoutem/cli 的问题。现在已经发布了一个较新的版本 (v0.8.143),它解决了这个问题。更新您的@shoutem/cli,您的构建应该没有错误。

    CLI 应该会在您下次使用时提示您更新它,所以只需使用

    $ shoutem -v
    

    将提示您选择是/否更新选项。

    如果您拒绝更新,则不会再次提示您,但会收到警告:

    “警告:这是一个过时版本的shoutem CLI”

    您可以安装最新版本:

    $ npm install -g @shoutem/cli
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      相关资源
      最近更新 更多