我已经设置了一个dockerfile和docker撰写文件的离子应用程序。我可以在我的计算机上使用放在my package.json上的“start”脚本进行测试:
{
"name": "CryptoWallet",
"version": "0.0.1",
"description": "",
"scripts": {
"start": "ionic serve --external",
"buildandroid": "ionic cordova build --release android"
},
"devDependencies": {
"cordova-android": "^9.0.0",
"gulp": "^3.5.6",
"gulp-clean-css": "^3.7.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "^3.1.0"
},
"dependencies": {
"@ionic/v1-toolkit": "^3.2.14",
"cordova": "^10.0.0",
"cordova-plugin-device": "^2.0.1",
"cordova-plugin-ionic-keyboard": "^2.0.5",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-res": "^0.15.2",
"ionic": "^5.4.16"
},
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {
},
"cordova-plugin-device": {
},
"cordova-plugin-splashscreen": {
},
"cordova-plugin-ionic-webview": {
},
"cordova-plugin-ionic-keyboard": {
}
},
"platforms": [
"android"
]
}
}
然后我想使用“buildandroid”脚本创建一个apk版本(ionic cordova build——release android)。如果我在docker之外做的话,它可以工作,但是apk当然没有所有的依赖项(只在docker内部设置),而且在我的android手机上安装之后,它也不能很好地工作。因此,我应该把androidsdk、jdk和gradle放在project文件夹中,一个接一个地复制到docker文件中。这是我的dockerfile.dev:
FROM node:13-alpine as build
WORKDIR /app
ENV JAVA_HOME /app/www/jdk1.8.0_211
ENV ANDROID_HOME /app/www/Sdk
ENV ANDROID_SDK_ROOT /app/www/Sdk
ENV PATH $PATH:/app/www/Sdk/platform-tools
ENV PATH $PATH:/app/www/jdk1.8.0_211/bin
ENV PATH $PATH:/app/www/gradle-6.7.1/bin
COPY package*.json /app/
RUN npm install --prefix ./www @gmwallet/lib@latest
RUN npm install --prefix ./www @gmwallet/app-common@latest
RUN npm install --save --prefix ./www angular-resource@1.4.8
COPY ./ ./
CMD ["npm", "run", "buildandroid"]
@gmwallet是我在npmjs上发布的项目依赖项,它们可以工作。sdk、jdk和gradle直接复制到我的应用程序的“www”文件夹中。环境变量直接指向docker中的这些文件夹(我试图在容器中找到它们,并成功地找到了它们)。实际上,我使用docker-compose.yml运行dockerfile:
version: "3"
services:
web:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "8100:8100"
volumes:
- /app/node_modules
- /app/www/lib/node_modules
- /app/www/node_modules
- .:/app
stdin_open: true
environment:
- CHOKIDAR_USEPOLLING=true
我遇到的问题是关于环境变量,它记录如下:
web_1 | Checking Java JDK and Android SDK versions
web_1 | ANDROID_SDK_ROOT=/app/www/Sdk (recommended setting)
web_1 | ANDROID_HOME=/app/www/Sdk (DEPRECATED)
web_1 | Failed to run "javac -version", make sure that you have a JDK version 8 installed.
web_1 | You can get it from the following location:
web_1 | https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
web_1 |
web_1 | Your JAVA_HOME is invalid: /app/www/jdk1.8.0_211
web_1 | [ERROR] An error occurred while running subprocess cordova.
web_1 |
web_1 | cordova build android --release exited with exit code 1.
web_1 |
web_1 | Re-running this command with the --verbose flag may provide more information.
web_1 | npm ERR! code ELIFECYCLE
web_1 | npm ERR! errno 1
web_1 | npm ERR! CryptoWallet@0.0.1 buildandroid: `ionic cordova build --release android`
web_1 | npm ERR! Exit status 1
web_1 | npm ERR!
web_1 | npm ERR! Failed at the CryptoWallet@0.0.1 buildandroid script.
web_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
web_1 |
web_1 | npm ERR! A complete log of this run can be found in:
web_1 | npm ERR! /root/.npm/_logs/2020-12-31T02_54_00_801Z-debug.log
cryptowallet_web_1 exited with code 1
问题是:如何为sdk和jdk定义一个有效的环境变量?也许使用npm run安装依赖项比将它们复制到文件夹更好(现在,这只是为了测试,如果它工作,我会把sdk和jdk在另一个库中的npmjs,以便安装其他的。我不知道,这很奇怪。环境变量设置得很好,并且文件夹存在于容器中。实际上,我用的是离子1。我在Windows10环境中使用docker桌面
暂无答案!
目前还没有任何答案,快来回答吧!