【问题标题】:Modify Android gradle.properties in Expo Managed App在 Expo Managed App 中修改 Android gradle.properties
【发布时间】:2022-09-29 03:08:07
【问题描述】:

我正在开发一个 Expo React Native 项目,该项目在 android 中需要高达 15MB 的本地存储空间。这需要将以下内容添加到 android/gradle.properties 文件中。

AsyncStorage_db_size_in_MB=10

我试过用

import { withGradleProperties } from \"@expo/config-plugins\";

export const modifyGradle = (config) => {
      const AsyncKey = \"AsyncStorage_db_size_in_MB\";
      return withGradleProperties(config, (config) => {
        config.modResults.push({
          type: \"property\",
          key: AsyncKey,
          value: 10,
        });
    
        return config;
      });
    };

然后添加到 app.json 作为

expo:{
...
\"plugins\": [\"./plugins/modifyGradle.js\"],
...
}  

我在这里做错了什么?在不退出世博会的情况下如何做到这一点?

    标签: android react-native expo asyncstorage


    【解决方案1】:

    问题是你的配置插件名称,它应该是“with Modify Gradle.js”

    Plugins should be named using the following convention: with<Plugin Functionality> i.e. withFacebook.
    

    https://docs.expo.dev/guides/config-plugins/#creating-a-plugin

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
    【解决方案2】:

    首先,@ 987654321@,你应该将你的插件重命名为withModifyGradle,据我所知,你不应该使用import,而是使用require:

    const { withGradleProperties } = require('@expo/config-plugins');
    
    module.exports = (config) => {
      const newGraddleProperties = [
        {
          type: 'property',
          key: 'AsyncStorage_db_size_in_MB',
          value: '10', // Maybe you should set this to 15?
        },
        // Added this to demostrate multiple gradle properties change
        {
          type: 'property',
          key: 'FLIPPER_VERSION',
         value: '0.144.0', // Fix app names with accented and diacritics characters
        },
      ];
    
      return withGradleProperties(config, (config) => {
        newGraddleProperties.map((gradleProperty) => config.modResults.push(gradleProperty));
    
        return config;
      });
    };
    

    创建配置插件后,将其设置为app.config.js(as stated here) 像这样

    expo:{
        ...
        plugins: [
            ['./plugins/withModifyGradle.js'],
        ],
        ...
    }  
    

    As stated here,您可以通过在项目目录中运行EXPO_DEBUG=1 expo prebuild 来检查插件是否工作。之后,你应该有一个安卓文件夹gradle.properties文件末尾带有新属性的文件。

    如果成功了,那么你就准备好了易建,但运行该命令后,我需要删除index.js、metro.config.js、android、ios 和 node_modules文件夹,并将更改还原到我的包.json文件,然后运行npm 安装回到世博会。

    【讨论】:

      猜你喜欢
      • 2021-11-27
      • 2023-02-24
      • 2022-10-17
      • 2023-02-18
      • 2019-11-08
      • 2021-03-04
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多