preface
The construction process is as follows
- Jenkins download and run
- Android Environment Configuration
- Create the Android project and project Build configuration
- Build the project
- conclusion
The environment is configured on the Mac, the Windows configuration has not been tried, there is time to study.
Jenkins download and run
Jenkins download
Jenkins is a standalone java-based application, so if you have Java installed on your computer, you should be able to run it in theory.
Jenkins is a standalone Java-based program that runs immediately and includes Windows, Mac OS X, and other Unix-like operating systems.
Jenkins can be installed in several ways; Corresponding installation packages for each system, through Docker images, war packages, etc. Compared with the war form, it seems to be more convenient, so I decided to use this method (mainly lazy). Download Jenkins’ war package first. There are various installation packages available on the Jenkins website. Since we are going to use the war package, download it, as shown in the red box below:
For some reason, this war is not big (60mb or so), but it takes hours to download.
Run Jenkins
After downloading, you can run happily, download down the package you casually placed, when you can find the line. Then we open the terminal and run:
Enter java-jar jenkins.war
Note that this command must be run in the current directory of jenkins.war otherwise it will not be found.
During the run, you might see something like this:
You can paste the password now and use it later. Of course, if it’s not convenient for you, you can look for it when you need to use it. There will be a prompt at the back.
Open your browser and type localhost:8080 in the address bar to begin our Jenkins tour. If all is well, the first screen you will see is the following to unlock Jenkins:
Above let input administrator password, is the above said that a string of password, stick out stick up, if can not find, the above provided view path (that line of red characters) go in to see and paste out.
Click “Continue” and the next screen will show you the option to install the plugin. We are new to this, so we will select the first recommended installation and put an image:
Then there is a long wait, will be installed many plug-ins, plug-in interface:
After it is installed, it will jump to an interface for filling in the account password. The account filled in here is the account we will log in later. According to the prompt information, fill in each item, save it, and there will be a page prompt after success. Now that the Jenkins installation is complete, it’s time to configure some environments and create projects.
Configure the Android compilation environment
After entering the Jenkins interface, we did not rush to create the project, but first went to configure the environment. In the left navigation bar of the interface, we found Manager Jenkins and then found Global Tool Configuration in the fourth item in the list. Click on the Java JDK and Gradle configuration environment, as shown below:
Configure the Java JDK:
- 1, name: write freely, no special provisions
- 2. Path: path of the local Java JDK
Here is the JDK path, macOS itself has a Java environment, you can use directly, maybe not the latest package, you can choose to upgrade, we will fill in this path. If you’ve configured Java environment variables locally, open the.bash_profile file, find the path to JAVA_HOME, copy it and place it here.
Open the command open ~/.bash_profile
Your configuration information might look like this, circled is the path we want:
If the local JDK doesn’t know where it is, look at it as follows:
Enter /usr/libexec/java_HOME -v and you will see the following:
From where the arrow points to, this is the path we’re going to configure. If you have multiple JDKS installed, multiple messages will be displayed. Use any one, depending on your choice.
Configuration Gradle:
- 1, name: write freely, no special provisions
- 2, Path: gradle path
Find the Gradle path
- Methods a
Gradle is located before Android Studio3.5
App --> Android Studio --> Right-click --> Show package Contents --> Contents --> Gradle
Find the location of Gradle and select the gradle version you want to use. You can paste the path as follows:
Select File -> right-click -> Show Introduction -> Location
Paste the path corresponding to the position; Alternatively, you can drag the gradle version folder of your choice into the terminal and copy the full path to position 2 in our image.
- Method 2
Alternatively, you can open your local. Gradle and get the version of Gradle you want to build from there. Since. Gradle files are hidden by default, we need to show the hidden files before we operate. The operation mode is as follows:
⌘ to show a hidden file shortcut: Command + Shift ⇧ +.(This will be done in the user’s root directory)
Once you have found the. Gradle file, do as follows:
Gradle --> wrapper --> dists --> your gradle list
Go to your Gradle list layer by layer as shown above, select the version you want, copy the path as shown in method 1 and place it in position 2.
- Methods three
If you find the above two methods too tedious, you can download Gradle in your configuration according to your project’s requirements, as shown in the following figure:
Add a name and select Install Automatically to select gradle versions. This will be used when your project is built.
At this point, our Gradle path is configured. Just click Sava and save.
Configure the Android SDK
Configuring the Android SDK and the preceding two configurations are not on the same page. Go back to Jenkins’ Settings screen, click Configure System to enter the Settings screen, locate the Global Properties property, check Environment Variables, and fill in the name and the path of the corresponding Android SDK:
- 1, check the
Environment variables
attribute - 2. Fill in your name
- 3. Enter the SDK path
The SDK path is also easy to find. Let’s open the Android Studio editor, go to the top toolbar, and find the SDK Manager button
Click on it, it will display all the SDK versions of Android, some of which we have downloaded, some of which we have not downloaded, but we are not concerned about this, we are concerned about the path circled in the red box, copy it, and place it at position 2, as follows:
Now that our Android environment is almost configured, we can create projects.
Create the Android project and project Build configuration
Create a project
With all the preparation done, let’s start creating the project and go back to the main page. As shown in the figure:
Just enter the name on the project, select Freestyle Project, and save. The project is created. Then enter the project we created and configure the items
Project configuration
General (General configuration)
The first item you see when you enter the project is the General option.
We now have the project configured, can run; More on parameterized builds later in the chapter. Just fill in the description here.
SCM (Source Code Management)
Next comes the SCM module, shown above:
Here, the warehouse address of the construction project is mainly set. SVN and Git can be selected. Here, SVN is taken as an example. Enter the SVN project address and select the SVN account. The default position of the SVN account is empty. Click the Add button to Add:
Add your account and password separately. After saving, you can select it on the front screen. Complete the address and SVN account. Retain the default values for other options. No further operations are required.
Next, the next two tabs Build Triggers,Build Environment Triggers, do not do any more filling in for now, just leave the default.
Build
This step specifies the Gradle version to be used to build the project. Click the Add Build step button to Add:
Select the Invoke Gradle Script option and you will see the options to fill in below
Select the name of Gradle you just named. In the Tasks TAB, write the Gradle command we want to execute. Do not check the Use Gradle Wrapper option. Tasks are below it but are not part of it:
The command in Tasks is the same as the command we enter at the end of the project;
For example, if you want to build a debug version of your project:
assembleDebug
The official version:
assembleRelease
Of course, if you have options packaged in the project, you can edit Flavors in Tasks as well. “Flavors” is “Xiaomi” and “Huawei”, and “Tasks” is “Tasks”.
AssembleXiaomiRelease and assembleHuaweiRelease.
There are several options about Flavors configuration that you can look forward to.
Gradle productFlavors can be packaged with multiple versions
At this point our project configuration is complete, click the Save button, and the final build step is ready.
Build the project
After saving, jump to the menu page of the project and click the “Build now” button to start the project:
During the build process, if you want to see the console logs, you can select the project being built, and the versions of each build are listed here.
Click on the small triangle behind the drop-down list, select the Console Output point to go to the project’s build log.
Wait until the project is built, and if you see the familiar information below, your project is built successfully.
If the project is not successfully constructed, the log will also give corresponding prompts, requiring us to solve as needed.
The workspace
The package is in the Work Space list.
Click on it to see that the directory structure is the same as our Android Studio directory structure, and the successful build file is also in the Build file, which is not described here.
conclusion
This is how Jenkins downloaded, installed, configured, and created the Android project. It introduced the basic building method. Later, we will introduce how to parameterize the building so that Jenkins can have more gameplay.