通过Shoutem平台修改AndroidManifest.xml

时间:2017-05-03 13:34:17

标签: android react-native shoutem

我想在这种情况下添加/修改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

1 个答案:

答案 0 :(得分:0)

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

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

$ shoutem -v

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

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

&#34;警告:这是shoutem CLI&#34;

的过时版本

您可以安装最新版本:

$ npm install -g @shoutem/cli