Offline Development Environment Setup for DevEco Studio
Setting up an offline development environment for DevEco Studio can be a bit challenging, but it is essential for scenarios where internet access is restricted or unavailable. This guide will walk you through the detailed steps required to install Hypium, third-party libraries, and other necessary dependencies in an offline environment. Additionally, it will cover how to set up an offline pipeline and install plugins like pnpm
offline.
Installing Hypium in an Offline Environment
-
Prepare Files on an Online Computer:
-
Create a Folder: Create a folder named
third_library
on an online computer. This folder will hold all the necessary files for offline installation. -
Create
oh-package.json5
File: Inside thethird_library
folder, create a file namedoh-package.json5
with the following content:
{ "dependencies": { "@ohos/hypium": "1.0.18" } }
-
Create a Folder: Create a folder named
-
Install Hypium: Open the command line and navigate to the
third_library
folder. Run the following command to install Hypium:
ohpm install
This command will generate an
oh_modules
folder and anoh-package-lock.json5
file. These files are crucial for offline installation. Ensure Environment Variables: Before running
ohpm install
, ensure that the environment variables forohpm
are correctly set on your system. This typically involves setting the path to theohpm
executable.
-
Transfer Files to Offline Computer:
-
Copy Files: Copy the
oh_modules
folder and theoh-package-lock.json5
file from thethird_library
folder on the online computer to the root directory of your project on the offline computer. -
Note: Ensure that the version of
ohpm
on both the online and offline computers is the same. Version mismatches can cause issues with theoh-package-lock.json5
file.
-
Copy Files: Copy the
Installing Third-Party Libraries
There are two methods to install third-party libraries in an offline environment: using a private repository or manual installation.
Method 1: Using a Private Repository
-
Set Up a Private Repository: Use
ohpm-repo
to set up a private repository. This repository will host the required third-party packages.
ohpm-repo init
- Publish Packages: Publish the required third-party packages to the private repository.
ohpm publish --registry <private-repo-url>
-
Configure
.ohpmrc
File: Replace theregistry
configuration in the.ohpmrc
file with the address of your private repository.
{
"registry": "http://<private-repo-url>"
}
Method 2: Manual Installation
-
Create
oh-package.json5
File: On an online computer, create a folder and anoh-package.json5
file with your dependencies. For example:
{
"dependencies": {
"@ohos/hypium": "1.0.17",
"@ohos/lottie": "^2.0.0"
}
}
-
Generate Modules: Run the following command to generate the
oh_modules
folder andoh-package-lock.json5
file:
ohpm install
-
Copy Files: Copy the
oh_modules
folder andoh-package-lock.json5
file to the root directory of your project on the offline computer. -
Ensure Version Match: Ensure that the
ohpm
versions on both the online and offline computers are the same to avoid version conflicts.
Setting Up an Offline Pipeline
For completely offline environments, you can set up a build pipeline. This involves creating a local repository of all necessary dependencies and configuring your build scripts to use this local repository. Refer to the official DevEco Studio documentation for detailed instructions on building and running applications in such environments.
Installing the pnpm
Plugin Offline
-
Create Folder and
package.json
File: On an online computer, create a folder and apackage.json
file with the following content:
{
"dependencies": {
"pnpm": "8.13.1"
}
}
-
Generate
node_modules
Folder: Run the following command to installpnpm
and generate thenode_modules
folder:
npm install
-
Copy Files: Copy the
node_modules
folder andpackage.json
file to the following directory on the offline computer:
C:\Users\<Username>\.hvigor\wrapper\tools
Create the directory if it does not exist.
- Enable npm Offline Mode: On the offline computer, run the following command to enable npm offline mode:
npm config set offline true
Installing npm Dependencies Offline
-
Create Folder and
package.json
File: On an online computer, create a folder and apackage.json
file with your dependencies. For example:
{
"dependencies": {
"ajv": "latest"
}
}
-
Generate
node_modules
Folder: Run the following command to install the dependencies and generate thenode_modules
folder:
npm install
-
Copy Files: Copy the
node_modules
folder to the root directory of your project on the offline computer.
Conclusion
Setting up an offline development environment for DevEco Studio involves several steps, including preparing and transferring necessary files, ensuring version consistency, and configuring build pipelines. By following the detailed steps outlined above, you can successfully install Hypium, third-party libraries, and other dependencies in an offline environment. This setup allows you to develop HarmonyOS applications even in scenarios with limited or no internet access.
Top comments (0)