📅  最后修改于: 2023-12-03 15:14:57.080000             🧑  作者: Mango
If you're a JavaScript developer building mobile apps using React Native, you've probably come across Expo, a popular toolchain and set of services that provides an easier dev experience in building, testing, deploying, and maintaining native mobile projects.
With Expo CLI, you can create, run, and develop standalone apps and run it using Expo client app or standalone. But if you want to build a production-ready APK file for your Android app, you'll need to run the expo build:android
command. Here's everything you need to know about that command:
To use any of the Expo CLI commands, you'll need to first have it installed on your machine. You can install it globally via npm:
npm install -g expo-cli
Once installed, you can verify the installation by running:
expo --version
You should see the version number printed on the console in a few moments.
Assuming you have already created your React Native project using create-react-native-app
or Expo CLI's init
command, you can navigate to your project directory and run:
expo build:android
This will prompt you to either login to Expo or create a new account to use in building your app.
Once you're authenticated and authorized to access the Expo servers, you'll need to configure your app for the build process. Expo CLI will prompt you to specify some options before starting the build:
URL: This is the URL of the app you want to build. You can set it to the URL where your app's JS bundle is hosted, which is usually the URL of your Expo project in the Expo client app. It can also be a local URL if you don't want to upload the entire app to Expo servers.
SDK Version: This is the version number of the Expo SDK you're using to build your app. You can choose the latest version or specify a version number if you're using an older version.
Build Type: This is the type of build you want to create. You can choose between a development or production build.
Keystore Alias: If you have an existing Android keystore file, you'll need to specify its alias here.
APK Output Path: This is the path and filename of the APK file you want to create. You can accept the default value or specify a custom path.
Once you've configured your app for building, Expo CLI will begin the build process. Depending on the size and complexity of your app, this can take a few minutes to complete.
After successful build, Expo CLI will provide you with a download link to your new APK file, which you can use to distribute your app to others or release it on the Google Play Store.
Expo's build:android
command is an essential tool for any React Native developer looking to release their app to production on the Android platform. By simplifying and automating many of the necessary steps in the building process, it makes it easier than ever to create a professional-quality APK file.
If you're a JavaScript developer new to React Native development, or you're looking to get up to speed on the latest tools and techniques for building mobile apps, be sure to explore the many resources and tutorials available on the Expo website and in the React Native community at large.
Happy coding!
Here's a sample expo build:android
configuration you can use:
{
"packagerOpts": {
"assetExts": ["ttf", "mp4"]
},
"android": {
"package": "com.yourcompany.yourappname",
"versionCode": 1,
"permissions": ["CAMERA", "ACCESS_FINE_LOCATION"],
"config": {
"googleSignIn": {
"apiKey": "<ANDROID_CLIENT_ID>",
"certificateHash": "<HASH_OF_SIGNING_CERTIFICATE>",
"hostedDomain": "gmail.com"
}
},
"googleServicesFile": "./google-services.json"
}
}
Be sure to modify the properties according to your app's requirements.