---- Updated at 2021-02-06
改用docker镜像来打包了
镜像源是最新ubuntu20.10
配置环境的脚本如下
([[ -f /etc/apt/sources.list.origin ]] || cp /etc/apt/sources.list /etc/apt/sources.list.origin)
sed -i 's/^\(deb\|deb-src\) \([^ ]*\) \(.*\)/\1 http:\/\/mirrors.aliyun.com\/ubuntu\/ \3/' /etc/apt/sources.list
apt update
apt install -y wget zip openjdk-8-jdk vim
apt install -y nodejs npm
apt install -y gradle
npm config set registry http://mirrors.cloud.tencent.com/npm/
npm i -g npm
npm i -g cordova
wget https://mirrors.cloud.tencent.com/AndroidSDK/sdk-tools-linux-4333796.zip
unzip -q sdk-tools-linux-4333796.zip
mkdir /usr/local/android-sdk-linux
mv tools /usr/local/android-sdk-linux
echo 'export SDK_HOME=/usr/local/android-sdk-linux' >> $HOME/.bashrc
echo 'export ANDROID_SDK_ROOT=$SDK_HOME' >> $HOME/.bashrc
echo 'export PATH=$SDK_HOME/tools/bin:$SDK_HOME/tools:$SDK_HOME/platform-tools:$PATH' >> $HOME/.bashrc
export SDK_HOME=/usr/local/android-sdk-linux
export ANDROID_SDK_ROOT=$SDK_HOME
export PATH=$SDK_HOME/tools/bin:$SDK_HOME/tools:$SDK_HOME/platform-tools:$PATH
sdkmanager "platform-tools" "platforms;android-29"
sdkmanager "build-tools;30.0.3"
mkdir $HOME/.gradle && cp init.gradle $HOME/.gradle/
cordova platform rm android
cordova platform add android
cordova build
Dockerfile内容
FROM ubuntu:groovy-20201125.2
MAINTAINER WJ
WORKDIR /app
COPY . .
ENV SDK_HOME=/usr/local/android-sdk-linux
ENV ANDROID_SDK_ROOT=$SDK_HOME
ENV PATH=$SDK_HOME/tools/bin:$SDK_HOME/tools:$SDK_HOME/platform-tools:$PATH
# initial
RUN ./factory_creator.sh
init.gradle内容
allprojects {
repositories {
def ALIYUN_REPOSITORY_URL = "http://maven.aliyun.com/nexus/content/groups/public"
def ALIYUN_JCENTER_URL = "http://maven.aliyun.com/nexus/content/repositories/jcenter"
def TX_REPOSITORY_URL = "http://mirrors.cloud.tencent.com/nexus/repository/maven-public/"
def TX_JCENTER_URL = "http://mirrors.cloud.tencent.com/nexus/repository/maven-jcenter/"
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith("https://repo1.maven.org/maven2")) {
project.logger.lifecycle "Repository ${repo.url} replaced by $TX_REPOSITORY_URL."
remove repo
}
if (url.startsWith("https://jcenter.bintray.com/")) {
project.logger.lifecycle "Repository ${repo.url} replaced by $TX_JCENTER_URL."
remove repo
}
}
}
maven {
url TX_REPOSITORY_URL
url TX_JCENTER_URL
}
}
}
分割线 ------------------------------------ 忽略下面的内容
---- Updated at 2020/07/17
文章不全, 缺了cordova requirements如何解决的描述
正在尝试用mac重新搭建。。。
ubuntu18 配置cordova的Android编译环境,大致命令如下:
sudo apt update
sudo apt install -y nodejs
# ---- Install yarn
sudo su
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update
apt install -y yarn
exit
# ----
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
yarn global add cordova
sudo apt install openjdk-8-jdk
# ---- Update nodejs and npm
sudo apt install -y npm
npm config set registry https://registry.npm.taobao.org
npm config get registry
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i -g npm
# ----
# ---- Install zsh
mkdir ~/softwares
cd ~/softwares
wget https://www.shequyi.fun/media/install-oh-my-zsh.sh
chmod +x install-oh-my-zsh.sh
./install-oh-my-zsh.sh
echo "[ -s \$HOME/.bash_aliases ] && source \$HOME/.bash_aliases" >> $HOME/.zshrc
echo "[ -s \$HOME/.local/bin ] && export PATH=\$HOME/.local/bin:/usr/local/bin:\$PATH" >> $HOME/.zshrc
# ----
# ---- Install and upgrade gradle
sudo apt install -y gradle
sudo apt install -y zip
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install gradle
sdk install groovy
# ----
# ---- Install android sdk
wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
tar -zxf android-sdk_r24.4.1-linux.tgz
sudo mv android-sdk-linux /usr/local
echo '# set PATH for android
export SDK_HOME=/usr/local/android-sdk-linux
if [ -d "$SDK_HOME/tools" ] ; then
PATH=$SDK_HOME/tools:$SDK_HOME/platform-tools:$PATH
fi
' >> ~/.zshrc
source ~/.zshrc
android update sdk --no-ui
# -----
# ----- Config gradle source mirror
echo 'allprojects {
repositories {
def ALIYUN_REPOSITORY_URL = "http://maven.aliyun.com/nexus/content/groups/public"
def ALIYUN_JCENTER_URL = "http://maven.aliyun.com/nexus/content/repositories/jcenter"
def TX_REPOSITORY_URL = "http://mirrors.cloud.tencent.com/nexus/repository/maven-public/"
def TX_JCENTER_URL = "http://mirrors.cloud.tencent.com/nexus/repository/maven-jcenter/"
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith("https://repo1.maven.org/maven2")) {
project.logger.lifecycle "Repository ${repo.url} replaced by $TX_REPOSITORY_URL."
remove repo
}
if (url.startsWith("https://jcenter.bintray.com/")) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
' > $HOME/.gradle/init.gradle
# ----
Usage
cordova create myapp
cd myapp
cordova platform add android
cordova build
Android WebViews https://cordova.apache.org/docs/en/9.x/guide/platforms/android/webview.html
find . -name 'framework'
# ./node_modules/cordova-android/framework
cd ./node_modules/cordova-android/framework
ant jar
ls
# cordova-8.0.0.jar ...
cd -
cp ./node_modules/cordova-android/framework/cordova-8.0.0.jar platforms/android/app/src/main/libs