admin管理员组文章数量:1432446
I need to add the following lines to the default config within my android build.gradle for my expo managed project
{ missingDimensionStrategy 'store', 'play' }
I believe I need to make a mod/plugin to add to this, but what would this look like?
Here is what I've tried to implement so far: /guides/config-plugins/#mod-plugins
using the withAppBuildGradle I believe is the best bet, but I'm not sure how to specifically add just the line in the android default config.
I need to add the following lines to the default config within my android build.gradle for my expo managed project
{ missingDimensionStrategy 'store', 'play' }
I believe I need to make a mod/plugin to add to this, but what would this look like?
Here is what I've tried to implement so far: https://docs.expo.dev/guides/config-plugins/#mod-plugins
using the withAppBuildGradle I believe is the best bet, but I'm not sure how to specifically add just the line in the android default config.
Share Improve this question asked Dec 28, 2022 at 16:24 guitarman0456guitarman0456 711 silver badge5 bronze badges3 Answers
Reset to default 4If the question is still valid, this is how you can achieve it using Expo modified flow. Starting from Expo SDK 41 you can use Config plugins
If you want to inject properties to android gradle this is how it can be achieved.
- Create a new file in a root directory called
injectedAndroidConfig.js
const { withAppBuildGradle } = require('@expo/config-plugins');
module.exports = function withAndroidStrategiesPlugin(config) {
return withAppBuildGradle(config, (config) => {
config.modResults.contents += `
android {
pileSdkVersion 31
buildToolsVersion "31.0.0"
defaultConfig {
targetSdkVersion 31
missingDimensionStrategy "store", "play"
}
}
`;
return config;
});
};
Here you can also set other properties you want (for example sdk version and so on)
- You should update your app.json to use your created plugin
{
"expo": {
"name": "appName",
[...]
"plugins": ["./injectedAndroidConfig", "react-native-iap"]
}
}
In case you are using this with react-native-iap
on Expo (which you probably are), you do not need to modify build.gradle. I fell into this trap and was stuck for 2+ hours.
Looking at the docs, in the FAQ there is a section about using it in Expo: https://react-native-iap.dooboolab./docs/faq#how-do-i-use-react-native-iap-in-expo
Tl/dr: Add the following to app.json
{
"expo": {
"plugins": ["react-native-iap"]
}
}
And rebuild your development build and it should all work, without any modification to build.gradle
Please note that react-native-iap
package cannot be used in the "Expo Go" app because it requires custom native code.
Following @AsMartynas answer, I've used his solution to add a dependecy in build.gradle. To insert the dependecy I had to do some string manipulation, finding the index of dependencies {
- which is the part of the file where dependencies lives - and replacing it with the content I needed.
Here's the final code
const { withAppBuildGradle } = require("@expo/config-plugins");
const PLAY_BILLING_LIBRARY_VERSION = "6.0.1"
module.exports = function withAndroidStrategiesPlugin(config) {
return withAppBuildGradle(config, (config) => {
const initialIndex = config.modResults.contents.indexOf("dependencies {");
// Add the billing dependency
config.modResults.contents =
config.modResults.contents.slice(0, initialIndex) +
`dependencies {
implementation(".android.billingclient:billing:${PLAY_BILLING_LIBRARY_VERSION}")` +
config.modResults.contents.slice(initialIndex + "dependencies {".length);
return config;
});
};
本文标签: javascriptHow can I add to default config in buildgradle in expo managed projectStack Overflow
版权声明:本文标题:javascript - How can I add to default config in build.gradle in expo managed project? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745584143a2664791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论