首页指南参考教程

Expo BuildProperties

一个配置插件,允许在预构建期间自定义原生构建属性。

Android
iOS
tvOS

expo-build-properties配置插件,在 预建 期间配置 android/gradle.properties 和 ios/Podfile.properties.json 目录的原生构建属性。

¥expo-build-properties is a config plugin configuring the native build properties of your android/gradle.properties and ios/Podfile.properties.json directories during Prebuild.

此配置插件配置 预构建命令 如何生成原生 android 和 ios 文件夹,因此不能与不运行 npx expo prebuild 的项目(裸项目)一起使用。

安装

¥Installation

Terminal
npx expo install expo-build-properties

用法

¥Usage

Example app.json with config plugin

app.json
{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 34,
            "targetSdkVersion": 34,
            "buildToolsVersion": "34.0.0"
          },
          "ios": {
            "deploymentTarget": "13.4"
          }
        }
      ]
    ]
  }
}
app.config.js
export default {
  expo: {
    plugins: [
      [
        'expo-build-properties',
        {
          android: {
            compileSdkVersion: 34,
            targetSdkVersion: 34,
            buildToolsVersion: '34.0.0',
          },
          ios: {
            deploymentTarget: '13.4',
          },
        },
      ],
    ],
  },
};

所有可配置的属性

¥All configurable properties

PluginConfigType 接口代表当前可用的配置属性。

¥PluginConfigType interface represents currently available configuration properties.

API

Methods

BuildProperties.withBuildProperties(config, props)

NameTypeDescription
configExpoConfig

Expo config for application.

propsPluginConfigType

Configuration for the build properties plugin.


Config plugin allowing customizing native Android and iOS build properties for managed apps.

Returns:

ExpoConfig

Interfaces

AndroidMavenRepository

AndroidMavenRepository Properties

NameTypeDescription
authentication
(optional)
'basic' | 'digest' | 'header'

The authentication scheme to use when accessing the Maven repository.

credentials
(optional)
AndroidMavenRepositoryCredentials

The credentials to use when accessing the Maven repository. May be of type PasswordCredentials, HttpHeaderCredentials, or AWSCredentials.

See: the authentication schemes section of Gradle documentation for more information.

urlstring

The URL of the Maven repository.


Only for:
iOS

ExtraIosPodDependency

Interface representing extra CocoaPods dependency.

See: Podfile syntax reference

ExtraIosPodDependency Properties

NameTypeDescription
branch
(optional)
string

The git branch to fetch. See the git property for more information.

commit
(optional)
string

The git commit to fetch. See the git property for more information.

configurations
(optional)
string[]

Build configurations for which the pod should be installed.

Example['Debug', 'Release']
git
(optional)
string

Use the bleeding edge version of a Pod.

Example{ "name": "AFNetworking", "git": "https://github.com/gowalla/AFNetworking.git", "tag": "0.7.0" }

This acts like to add this pod dependency statement:

pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'
modular_headers
(optional)
boolean

Whether this pod should use modular headers.

namestring

Name of the pod.

path
(optional)
string

Custom local filesystem path to add the dependency.

Example~/Documents/AFNetworking
podspec
(optional)
string

Custom podspec path.

Example

https://example.com/JSONKit.podspec

source
(optional)
string

Custom source to search for this dependency.

Examplehttps://github.com/CocoaPods/Specs.git
tag
(optional)
string

The git tag to fetch. See the git property for more information.

testspecs
(optional)
string[]

Test specs can be optionally included via the :testspecs option. By default, none of a Pod's test specs are included.

Example['UnitTests', 'SomeOtherTests']
version
(optional)
string

Version of the pod. CocoaPods supports various versioning options.

Example~> 0.1.2

PluginConfigType

Interface representing base build properties configuration.

PluginConfigType Properties

NameTypeDescription
android
(optional)
PluginConfigTypeAndroid
Only for:
Android

Interface representing available configuration for Android native build properties.

ios
(optional)
PluginConfigTypeIos
Only for:
iOS

Interface representing available configuration for iOS native build properties.


Only for:
Android

PluginConfigTypeAndroid

Interface representing available configuration for Android native build properties.

PluginConfigTypeAndroid Properties

NameTypeDescription
buildToolsVersion
(optional)
string

Override the default buildToolsVersion version number in build.gradle.

compileSdkVersion
(optional)
number

Override the default compileSdkVersion version number in build.gradle.

enablePngCrunchInReleaseBuilds
(optional)
boolean

Enable crunchPngs in release builds to optimize PNG files. This property is enabled by default, but "might inflate PNG files that are already compressed", so you may want to disable it if you do your own PNG optimization.

Default: true
enableProguardInReleaseBuilds
(optional)
boolean

Enable Proguard or R8 in release builds to obfuscate Java code and reduce app size.

enableShrinkResourcesInReleaseBuilds
(optional)
boolean

Enable shrinkResources in release builds to remove unused resources from the app. This property should be used in combination with enableProguardInReleaseBuilds.

extraMavenRepos
(optional)
(string | AndroidMavenRepository)[]

Add extra maven repositories to all gradle projects.

Takes an array of objects or strings. Strings are passed as the url property of the object with no credentials or authentication scheme.

This adds the following code to android/build.gradle:

allprojects {
 repositories {
  maven {
   url "https://foo.com/maven-releases"
 }
}

By using an AndroidMavenRepository object, you can specify credentials and an authentication scheme.

allprojects {
  repositories {
    maven {
      url "https://foo.com/maven-releases"
      credentials {
       username = "bar"
       password = "baz"
      }
      authentication {
       basic(BasicAuthentication)
      }
    }
  }
}
extraProguardRules
(optional)
string

Append custom Proguard rules to android/app/proguard-rules.pro.

kotlinVersion
(optional)
string

Override the Kotlin version used when building the app.

manifestQueries
(optional)
PluginConfigTypeAndroidQueries

Specifies the set of other apps that an app intends to interact with. These other apps are specified by package name, by intent signature, or by provider authority.

minSdkVersion
(optional)
number

Override the default minSdkVersion version number in build.gradle.

networkInspector
(optional)
boolean

Enable the Network Inspector.

Default: true
newArchEnabled
(optional)
boolean

Enable React Native new architecture for Android platform.

packagingOptions
(optional)
PluginConfigTypeAndroidPackagingOptions

Interface representing available configuration for Android Gradle plugin PackagingOptions.

targetSdkVersion
(optional)
number

Override the default targetSdkVersion version number in build.gradle.

useLegacyPackaging
(optional)
boolean

Instructs the Android Gradle plugin to compress native libraries in the APK using the legacy packaging system.

Default: false
usesCleartextTraffic
(optional)
boolean

Indicates whether the app intends to use cleartext network traffic.

Default: false

Only for:
Android

PluginConfigTypeAndroidPackagingOptions

Interface representing available configuration for Android Gradle plugin PackagingOptions.

PluginConfigTypeAndroidPackagingOptions Properties

NameTypeDescription
doNotStrip
(optional)
string[]

Array of patterns for native libraries that should not be stripped of debug symbols.

exclude
(optional)
string[]

Array of patterns for native libraries that should be excluded from being packaged in the APK.

merge
(optional)
string[]

Array of patterns for native libraries where all occurrences are concatenated and packaged in the APK.

pickFirst
(optional)
string[]

Array of patterns for native libraries where only the first occurrence is packaged in the APK.


PluginConfigTypeAndroidQueries

PluginConfigTypeAndroidQueries Properties

NameTypeDescription
intent
(optional)
PluginConfigTypeAndroidQueriesIntent[]

Specifies an intent filter signature. Your app can discover other apps that have matching <intent-filter> elements. These intents have restrictions compared to typical intent filter signatures.

See: Android documentation for details

package
(optional)
string[]

Specifies one or more apps that your app intends to access. These other apps might integrate with your app, or your app might use services that these other apps provide.

provider
(optional)
string[]

Specifies one or more content provider authorities. Your app can discover other apps whose content providers use the specified authorities. There are some restrictions on the options that you can include in this <provider> element, compared to a typical <provider> manifest element. You may only specify the android:authorities attribute.


PluginConfigTypeAndroidQueriesData

PluginConfigTypeAndroidQueriesData Properties

NameTypeDescription
host
(optional)
string

Specify a URI authority host that is handled

mimeType
(optional)
string

Specify a MIME type that is handled

scheme
(optional)
string

Specify a URI scheme that is handled


PluginConfigTypeAndroidQueriesIntent

PluginConfigTypeAndroidQueriesIntent Properties

NameTypeDescription
action
(optional)
string

A string naming the action to perform. Usually one of the platform-defined values, such as ACTION_SEND or ACTION_VIEW

category
(optional)
string | string[]

Provides an additional way to characterize the activity handling the intent, usually related to the user gesture or location from which it's started.

data
(optional)
PluginConfigTypeAndroidQueriesData

A description of the data associated with the intent.


Only for:
iOS

PluginConfigTypeIos

Interface representing available configuration for iOS native build properties.

PluginConfigTypeIos Properties

NameTypeDescription
ccacheEnabled
(optional)
boolean

Enable C++ compiler cache for iOS builds.

This speeds up compiling C++ code by caching the results of previous compilations.

See: - https://reactnative.dev/docs/build-speed#local-caches

  • https://ccache.dev/
deploymentTarget
(optional)
string

Override the default iOS "Deployment Target" version in the following projects:

  • in CocoaPods projects,
  • PBXNativeTarget with "com.apple.product-type.application" productType in the app project.
extraPods
(optional)
ExtraIosPodDependency[]

Add extra CocoaPods dependencies for all targets.

This acts like to add the following code to ios/Podfile:

pod '[EXTRA_POD_NAME]', '~> [EXTRA_POD_VERSION]' # e.g. pod 'Protobuf', '~> 3.14.0'
networkInspector
(optional)
boolean

Enable the Network Inspector.

Default: true
newArchEnabled
(optional)
boolean

Enable React Native new architecture for iOS platform.

privacyManifestAggregationEnabled
(optional)
boolean

Enable aggregation of Privacy Manifests (PrivacyInfo.xcprivacy) from CocoaPods resource bundles. If enabled, the manifests will be merged into a single file. If not enabled, developers will need to manually aggregate them.

useFrameworks
(optional)
'static' | 'dynamic'

Enable use_frameworks! in Podfile to use frameworks instead of static libraries for Pods.


Expo 中文网 - 粤ICP备13048890号