DEV Community

Cover image for No guidance on network environment configuration
liu yang
liu yang

Posted on • Edited on

No guidance on network environment configuration

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

  1. 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 the third_library folder, create a file named oh-package.json5 with the following content:
     {
       "dependencies": {
         "@ohos/hypium": "1.0.18"
       }
     }
    
  • 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 an oh-package-lock.json5 file. These files are crucial for offline installation.

  • Ensure Environment Variables: Before running ohpm install, ensure that the environment variables for ohpm are correctly set on your system. This typically involves setting the path to the ohpm executable.

  1. Transfer Files to Offline Computer:
    • Copy Files: Copy the oh_modules folder and the oh-package-lock.json5 file from the third_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 the oh-package-lock.json5 file.

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
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Publish Packages: Publish the required third-party packages to the private repository.
   ohpm publish --registry <private-repo-url>
Enter fullscreen mode Exit fullscreen mode
  1. Configure .ohpmrc File: Replace the registry configuration in the .ohpmrc file with the address of your private repository.
   {
     "registry": "http://<private-repo-url>"
   }
Enter fullscreen mode Exit fullscreen mode
Method 2: Manual Installation
  1. Create oh-package.json5 File: On an online computer, create a folder and an oh-package.json5 file with your dependencies. For example:
   {
     "dependencies": {
       "@ohos/hypium": "1.0.17",
       "@ohos/lottie": "^2.0.0"
     }
   }
Enter fullscreen mode Exit fullscreen mode
  1. Generate Modules: Run the following command to generate the oh_modules folder and oh-package-lock.json5 file:
   ohpm install
Enter fullscreen mode Exit fullscreen mode
  1. Copy Files: Copy the oh_modules folder and oh-package-lock.json5 file to the root directory of your project on the offline computer.
  2. 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

  1. Create Folder and package.json File: On an online computer, create a folder and a package.json file with the following content:
   {
     "dependencies": {
       "pnpm": "8.13.1"
     }
   }
Enter fullscreen mode Exit fullscreen mode
  1. Generate node_modules Folder: Run the following command to install pnpm and generate the node_modules folder:
   npm install
Enter fullscreen mode Exit fullscreen mode
  1. Copy Files: Copy the node_modules folder and package.json file to the following directory on the offline computer:
   C:\Users\<Username>\.hvigor\wrapper\tools
Enter fullscreen mode Exit fullscreen mode

Create the directory if it does not exist.

  1. Enable npm Offline Mode: On the offline computer, run the following command to enable npm offline mode:
   npm config set offline true
Enter fullscreen mode Exit fullscreen mode

Installing npm Dependencies Offline

  1. Create Folder and package.json File: On an online computer, create a folder and a package.json file with your dependencies. For example:
   {
     "dependencies": {
       "ajv": "latest"
     }
   }
Enter fullscreen mode Exit fullscreen mode
  1. Generate node_modules Folder: Run the following command to install the dependencies and generate the node_modules folder:
   npm install
Enter fullscreen mode Exit fullscreen mode
  1. 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)