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_libraryon an online computer. This folder will hold all the necessary files for offline installation. -
Create
oh-package.json5File: Inside thethird_libraryfolder, create a file namedoh-package.json5with 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_libraryfolder. Run the following command to install Hypium:
ohpm installThis command will generate an
oh_modulesfolder and anoh-package-lock.json5file. These files are crucial for offline installation. Ensure Environment Variables: Before running
ohpm install, ensure that the environment variables forohpmare correctly set on your system. This typically involves setting the path to theohpmexecutable.
-
Transfer Files to Offline Computer:
-
Copy Files: Copy the
oh_modulesfolder and theoh-package-lock.json5file from thethird_libraryfolder on the online computer to the root directory of your project on the offline computer. -
Note: Ensure that the version of
ohpmon both the online and offline computers is the same. Version mismatches can cause issues with theoh-package-lock.json5file.
-
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-repoto 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
.ohpmrcFile: Replace theregistryconfiguration in the.ohpmrcfile with the address of your private repository.
{
"registry": "http://<private-repo-url>"
}
Method 2: Manual Installation
-
Create
oh-package.json5File: On an online computer, create a folder and anoh-package.json5file 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_modulesfolder andoh-package-lock.json5file:
ohpm install
-
Copy Files: Copy the
oh_modulesfolder andoh-package-lock.json5file to the root directory of your project on the offline computer. -
Ensure Version Match: Ensure that the
ohpmversions 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.jsonFile: On an online computer, create a folder and apackage.jsonfile with the following content:
{
"dependencies": {
"pnpm": "8.13.1"
}
}
-
Generate
node_modulesFolder: Run the following command to installpnpmand generate thenode_modulesfolder:
npm install
-
Copy Files: Copy the
node_modulesfolder andpackage.jsonfile 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.jsonFile: On an online computer, create a folder and apackage.jsonfile with your dependencies. For example:
{
"dependencies": {
"ajv": "latest"
}
}
-
Generate
node_modulesFolder: Run the following command to install the dependencies and generate thenode_modulesfolder:
npm install
-
Copy Files: Copy the
node_modulesfolder 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)