Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4b06eecf3e | ||
![]() |
5a9eb154e0 | ||
![]() |
655c018272 | ||
![]() |
214e857b20 | ||
![]() |
c7b0b93c9d |
46
.asf.yaml
@ -1,46 +0,0 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
github:
|
|
||||||
description: Apache Cordova Android
|
|
||||||
homepage: https://cordova.apache.org/
|
|
||||||
|
|
||||||
labels:
|
|
||||||
- cordova
|
|
||||||
- cordova-platform
|
|
||||||
- android
|
|
||||||
- java
|
|
||||||
- mobile
|
|
||||||
- javascript
|
|
||||||
- nodejs
|
|
||||||
- hacktoberfest
|
|
||||||
|
|
||||||
features:
|
|
||||||
wiki: false
|
|
||||||
issues: true
|
|
||||||
projects: true
|
|
||||||
|
|
||||||
enabled_merge_buttons:
|
|
||||||
squash: true
|
|
||||||
merge: false
|
|
||||||
rebase: false
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
commits: commits@cordova.apache.org
|
|
||||||
issues: issues@cordova.apache.org
|
|
||||||
pullrequests_status: issues@cordova.apache.org
|
|
||||||
pullrequests_comment: issues@cordova.apache.org
|
|
@ -1,3 +1 @@
|
|||||||
templates/project/assets/www/cordova.js
|
bin/templates/project/assets/www/cordova.js
|
||||||
test/android/app
|
|
||||||
test/androidx/app
|
|
@ -1,27 +1,10 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
root: true
|
||||||
# or more contributor license agreements. See the NOTICE file
|
extends: semistandard
|
||||||
# distributed with this work for additional information
|
rules:
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
indent:
|
||||||
# to you under the Apache License, Version 2.0 (the
|
- error
|
||||||
# "License"); you may not use this file except in compliance
|
- 4
|
||||||
# with the License. You may obtain a copy of the License at
|
camelcase: off
|
||||||
#
|
padded-blocks: off
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
operator-linebreak: off
|
||||||
#
|
no-throw-literal: off
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
extends: '@cordova/eslint-config/node'
|
|
||||||
|
|
||||||
overrides:
|
|
||||||
- files: [spec/**/*.js]
|
|
||||||
extends: '@cordova/eslint-config/node-tests'
|
|
||||||
rules:
|
|
||||||
prefer-promise-reject-errors: off
|
|
||||||
|
|
||||||
- files: [cordova-js-src/**/*.js]
|
|
||||||
extends: '@cordova/eslint-config/browser'
|
|
||||||
|
42
.github/ISSUE_TEMPLATE.md
vendored
@ -1,42 +0,0 @@
|
|||||||
<!--
|
|
||||||
Please have a look at the issue templates you get when you click "New issue" in the GitHub UI.
|
|
||||||
We very much prefer issues created by using one of these templates.
|
|
||||||
-->
|
|
||||||
|
|
||||||
### Issue Type
|
|
||||||
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
|
|
||||||
|
|
||||||
- [ ] Bug Report
|
|
||||||
- [ ] Feature Request
|
|
||||||
- [ ] Support Question
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
## Information
|
|
||||||
<!-- Include all relevant information that might help understand and reproduce the problem -->
|
|
||||||
|
|
||||||
### Command or Code
|
|
||||||
<!-- What command or code is needed to reproduce the problem? -->
|
|
||||||
|
|
||||||
### Environment, Platform, Device
|
|
||||||
<!-- In what environment, on what platform or on which device are you experiencing the issue? -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Version information
|
|
||||||
<!--
|
|
||||||
What are relevant versions you are using?
|
|
||||||
For example:
|
|
||||||
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
|
|
||||||
Other Frameworks: Ionic Framework and CLI version
|
|
||||||
Operating System, Android Studio, Xcode etc.
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Checklist
|
|
||||||
<!-- Please check the boxes by putting an `x` in the `[ ]` like so: `[x]` -->
|
|
||||||
|
|
||||||
- [ ] I searched for already existing GitHub issues about this
|
|
||||||
- [ ] I updated all Cordova tooling to their most recent version
|
|
||||||
- [ ] I included all the necessary information above
|
|
50
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
@ -1,50 +0,0 @@
|
|||||||
---
|
|
||||||
name: 🐛 Bug Report
|
|
||||||
about: If something isn't working as expected.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Bug Report
|
|
||||||
|
|
||||||
## Problem
|
|
||||||
|
|
||||||
### What is expected to happen?
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### What does actually happen?
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Information
|
|
||||||
<!-- Include all relevant information that might help understand and reproduce the problem -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Command or Code
|
|
||||||
<!-- What command or code is needed to reproduce the problem? -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Environment, Platform, Device
|
|
||||||
<!-- In what environment, on what platform or on which device are you experiencing the issue? -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Version information
|
|
||||||
<!--
|
|
||||||
What are relevant versions you are using?
|
|
||||||
For example:
|
|
||||||
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
|
|
||||||
Other Frameworks: Ionic Framework and CLI version
|
|
||||||
Operating System, Android Studio, Xcode etc.
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Checklist
|
|
||||||
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
|
|
||||||
|
|
||||||
- [ ] I searched for existing GitHub issues
|
|
||||||
- [ ] I updated all Cordova tooling to most recent version
|
|
||||||
- [ ] I included all the necessary information above
|
|
29
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
name: 🚀 Feature Request
|
|
||||||
about: A suggestion for a new functionality
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Feature Request
|
|
||||||
|
|
||||||
## Motivation Behind Feature
|
|
||||||
<!-- Why should this feature be implemented? What problem does it solve? -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Feature Description
|
|
||||||
<!--
|
|
||||||
Describe your feature request in detail
|
|
||||||
Please provide any code examples or screenshots of what this feature would look like
|
|
||||||
Are there any drawbacks? Will this break anything for existing users?
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Alternatives or Workarounds
|
|
||||||
<!--
|
|
||||||
Describe alternatives or workarounds you are currently using
|
|
||||||
Are there ways to do this with existing functionality?
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
27
.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md
vendored
@ -1,27 +0,0 @@
|
|||||||
---
|
|
||||||
name: 💬 Support Question
|
|
||||||
about: If you have a question, please check out our Slack or StackOverflow!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<!------------^ Click "Preview" for a nicer view! -->
|
|
||||||
|
|
||||||
Apache Cordova uses GitHub Issues as a feature request and bug tracker _only_.
|
|
||||||
For usage and support questions, please check out the resources below. Thanks!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
You can get answers to your usage and support questions about **Apache Cordova** on:
|
|
||||||
|
|
||||||
* Slack Community Chat: https://cordova.slack.com (you can sign-up at http://slack.cordova.io/)
|
|
||||||
* StackOverflow: https://stackoverflow.com/questions/tagged/cordova using the tag `cordova`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
If you are using a tool that uses Cordova internally, like e.g. Ionic, check their support channels:
|
|
||||||
|
|
||||||
* **Ionic Framework**
|
|
||||||
* [Ionic Community Forum](https://forum.ionicframework.com/)
|
|
||||||
* [Ionic Worldwide Slack](https://ionicworldwide.herokuapp.com/)
|
|
||||||
* **PhoneGap**
|
|
||||||
* [PhoneGap Developer Community](https://forums.adobe.com/community/phonegap)
|
|
27
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,5 +1,6 @@
|
|||||||
<!--
|
<!--
|
||||||
Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines:
|
Please make sure the checklist boxes are all checked before submitting the PR. The checklist
|
||||||
|
is intended as a quick reference, for complete details please see our Contributor Guidelines:
|
||||||
|
|
||||||
http://cordova.apache.org/contribute/contribute_guidelines.html
|
http://cordova.apache.org/contribute/contribute_guidelines.html
|
||||||
|
|
||||||
@ -9,27 +10,13 @@ Thanks!
|
|||||||
### Platforms affected
|
### Platforms affected
|
||||||
|
|
||||||
|
|
||||||
|
### What does this PR do?
|
||||||
### Motivation and Context
|
|
||||||
<!-- Why is this change required? What problem does it solve? -->
|
|
||||||
<!-- If it fixes an open issue, please link to the issue here. -->
|
|
||||||
|
|
||||||
|
|
||||||
|
### What testing has been done on this change?
|
||||||
### Description
|
|
||||||
<!-- Describe your changes in detail -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Testing
|
|
||||||
<!-- Please describe in detail how you tested your changes. -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Checklist
|
### Checklist
|
||||||
|
- [ ] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
|
||||||
- [ ] I've run the tests to see all new and existing tests pass
|
- [ ] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
|
||||||
- [ ] I added automated test coverage as appropriate for this change
|
- [ ] Added automated test coverage as appropriate for this change.
|
||||||
- [ ] Commit is prefixed with `(platform)` if this change only applies to one platform (e.g. `(android)`)
|
|
||||||
- [ ] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/))
|
|
||||||
- [ ] I've updated the documentation if necessary
|
|
||||||
|
64
.github/workflows/ci.yml
vendored
@ -1,64 +0,0 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
name: Node CI
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: NodeJS ${{ matrix.node-version }} on ${{ matrix.os }}
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [16.x, 18.x, 20.x]
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
|
|
||||||
- name: set up JDK 11
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '11'
|
|
||||||
|
|
||||||
- name: Environment Information
|
|
||||||
run: |
|
|
||||||
node --version
|
|
||||||
npm --version
|
|
||||||
gradle --version
|
|
||||||
|
|
||||||
- name: npm install and test
|
|
||||||
run: |
|
|
||||||
npm i
|
|
||||||
npm t
|
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: upload coverage
|
|
||||||
if: success()
|
|
||||||
uses: codecov/codecov-action@v3
|
|
||||||
with:
|
|
||||||
name: ${{ runner.os }} node.js ${{ matrix.node-version }}
|
|
110
.gitignore
vendored
@ -25,16 +25,11 @@ example
|
|||||||
/framework/libs
|
/framework/libs
|
||||||
/framework/javadoc-public
|
/framework/javadoc-public
|
||||||
/framework/javadoc-private
|
/framework/javadoc-private
|
||||||
|
|
||||||
**/assets/www/cordova.js
|
|
||||||
|
|
||||||
/test/.externalNativeBuild
|
/test/.externalNativeBuild
|
||||||
|
/test/build.gradle
|
||||||
/test/androidx/gradle
|
/test/gradle
|
||||||
/test/androidx/gradlew
|
/test/gradlew
|
||||||
/test/androidx/gradlew.bat
|
/test/gradlew.bat
|
||||||
/test/androidx/cdv-gradle-config.json
|
|
||||||
|
|
||||||
/test/assets/www/.tmp*
|
/test/assets/www/.tmp*
|
||||||
/test/assets/www/cordova.js
|
/test/assets/www/cordova.js
|
||||||
/test/bin
|
/test/bin
|
||||||
@ -48,10 +43,93 @@ tmp/**/*
|
|||||||
**/.idea/**/*
|
**/.idea/**/*
|
||||||
*.iml
|
*.iml
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
node_modules/
|
node_modules/jshint
|
||||||
coverage/
|
node_modules/promise-matchers
|
||||||
.nyc_output/
|
node_modules/jasmine
|
||||||
# Eclipse Buildship files
|
node_modules/rewire
|
||||||
.project
|
node_modules/istanbul
|
||||||
.settings
|
node_modules/.bin/cake
|
||||||
.classpath
|
node_modules/.bin/coffee
|
||||||
|
node_modules/.bin/escodegen
|
||||||
|
node_modules/.bin/esgenerate
|
||||||
|
node_modules/.bin/esparse
|
||||||
|
node_modules/.bin/esvalidate
|
||||||
|
node_modules/.bin/handlebars
|
||||||
|
node_modules/.bin/istanbul
|
||||||
|
node_modules/.bin/jasmine
|
||||||
|
node_modules/.bin/js-yaml
|
||||||
|
node_modules/.bin/jshint
|
||||||
|
node_modules/.bin/mkdirp
|
||||||
|
node_modules/.bin/r.js
|
||||||
|
node_modules/.bin/r_js
|
||||||
|
node_modules/.bin/strip-json-comments
|
||||||
|
node_modules/.bin/uglifyjs
|
||||||
|
node_modules/.bin/which
|
||||||
|
node_modules/align-text/
|
||||||
|
node_modules/amdefine/
|
||||||
|
node_modules/argparse/
|
||||||
|
node_modules/async/
|
||||||
|
node_modules/camelcase/
|
||||||
|
node_modules/center-align/
|
||||||
|
node_modules/cli/
|
||||||
|
node_modules/cliui/
|
||||||
|
node_modules/coffee-script/
|
||||||
|
node_modules/console-browserify/
|
||||||
|
node_modules/core-util-is/
|
||||||
|
node_modules/date-now/
|
||||||
|
node_modules/decamelize/
|
||||||
|
node_modules/deep-is/
|
||||||
|
node_modules/dom-serializer/
|
||||||
|
node_modules/domelementtype/
|
||||||
|
node_modules/domhandler/
|
||||||
|
node_modules/domutils/
|
||||||
|
node_modules/entities/
|
||||||
|
node_modules/escodegen/
|
||||||
|
node_modules/esprima/
|
||||||
|
node_modules/estraverse/
|
||||||
|
node_modules/esutils/
|
||||||
|
node_modules/exit/
|
||||||
|
node_modules/fast-levenshtein/
|
||||||
|
node_modules/fileset/
|
||||||
|
node_modules/gaze/
|
||||||
|
node_modules/growl/
|
||||||
|
node_modules/handlebars/
|
||||||
|
node_modules/has-flag/
|
||||||
|
node_modules/htmlparser2/
|
||||||
|
node_modules/is-buffer/
|
||||||
|
node_modules/isarray/
|
||||||
|
node_modules/isexe/
|
||||||
|
node_modules/jasmine-growl-reporter/
|
||||||
|
node_modules/jasmine-reporters/
|
||||||
|
node_modules/js-yaml/
|
||||||
|
node_modules/kind-of/
|
||||||
|
node_modules/lazy-cache/
|
||||||
|
node_modules/levn/
|
||||||
|
node_modules/longest/
|
||||||
|
node_modules/lru-cache/
|
||||||
|
node_modules/minimist/
|
||||||
|
node_modules/mkdirp/
|
||||||
|
node_modules/optimist/
|
||||||
|
node_modules/optionator/
|
||||||
|
node_modules/prelude-ls/
|
||||||
|
node_modules/readable-stream/
|
||||||
|
node_modules/repeat-string/
|
||||||
|
node_modules/requirejs/
|
||||||
|
node_modules/resolve/
|
||||||
|
node_modules/right-align/
|
||||||
|
node_modules/sigmund/
|
||||||
|
node_modules/source-map/
|
||||||
|
node_modules/sprintf-js/
|
||||||
|
node_modules/string_decoder/
|
||||||
|
node_modules/strip-json-comments/
|
||||||
|
node_modules/supports-color/
|
||||||
|
node_modules/type-check/
|
||||||
|
node_modules/uglify-js/
|
||||||
|
node_modules/uglify-to-browserify/
|
||||||
|
node_modules/walkdir/
|
||||||
|
node_modules/which/
|
||||||
|
node_modules/window-size/
|
||||||
|
node_modules/wordwrap/
|
||||||
|
node_modules/yargs/
|
||||||
|
node_modules/jasmine-core/
|
||||||
|
node_modules/fs.realpath/
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
.*
|
|
||||||
coverage
|
|
||||||
test
|
|
||||||
spec
|
|
||||||
framework/build
|
|
||||||
cordova-js-src
|
|
@ -1,8 +1,8 @@
|
|||||||
*.properties
|
*.properties
|
||||||
templates
|
bin
|
||||||
gen
|
gen
|
||||||
proguard-project.txt
|
proguard-project.txt
|
||||||
spec
|
spec
|
||||||
|
appveyor.yml
|
||||||
framework/build
|
framework/build
|
||||||
ic_launcher.png
|
ic_launcher.png
|
||||||
build
|
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
GUESS_FIELDS = True
|
GUESS_FIELDS = True
|
||||||
OPEN_BROWSER = True
|
OPEN_BROWSER = True
|
||||||
TARGET_GROUPS = 'cordova'
|
TARGET_GROUPS = 'cordova'
|
||||||
REVIEWBOARD_URL = 'https://reviews.apache.org'
|
REVIEWBOARD_URL = 'http://reviews.apache.org'
|
||||||
|
|
||||||
|
28
.travis.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
language: android
|
||||||
|
sudo: false
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- ANDROID_TOOLS=${ANDROID_HOME}/tools
|
||||||
|
before_install:
|
||||||
|
- nvm install 6
|
||||||
|
# ensure at least gradle 3.3 is in place.
|
||||||
|
- wget http://services.gradle.org/distributions/gradle-3.3-bin.zip
|
||||||
|
- unzip gradle-3.3-bin.zip
|
||||||
|
- export GRADLE_HOME=$PWD/gradle-3.3
|
||||||
|
- export PATH=${GRADLE_HOME}/bin:${ANDROID_HOME}:${ANDROID_HOME}/emulator:${ANDROID_TOOLS}:${ANDROID_TOOLS}/bin:${ANDROID_HOME}/platform-tools:$PATH
|
||||||
|
- node --version
|
||||||
|
- gradle --version
|
||||||
|
- echo y | android --silent update sdk --no-ui --all --filter platform-tools,tools,build-tools-26.0.2,android-26,android-25,extra-google-m2repository,extra-android-m2repository
|
||||||
|
android:
|
||||||
|
components:
|
||||||
|
- tools
|
||||||
|
install:
|
||||||
|
- npm install
|
||||||
|
- npm install -g codecov
|
||||||
|
script:
|
||||||
|
- npm test
|
||||||
|
- npm run cover
|
||||||
|
after_script:
|
||||||
|
- codecov
|
@ -30,7 +30,8 @@ For instructions on this, start with the
|
|||||||
[contribution overview](http://cordova.apache.org/contribute/).
|
[contribution overview](http://cordova.apache.org/contribute/).
|
||||||
|
|
||||||
The details are explained there, but the important items are:
|
The details are explained there, but the important items are:
|
||||||
- Check for Github issues that corresponds to your contribution and link or create them if necessary.
|
- Sign and submit an Apache ICLA (Contributor License Agreement).
|
||||||
|
- Have a Jira issue open that corresponds to your contribution.
|
||||||
- Run the tests so your patch doesn't break existing functionality.
|
- Run the tests so your patch doesn't break existing functionality.
|
||||||
|
|
||||||
We look forward to your contributions!
|
We look forward to your contributions!
|
||||||
|
114
LICENSE
@ -187,7 +187,7 @@
|
|||||||
same "printed page" as the copyright notice for easier
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright 2015-2020 Apache Cordova
|
Copyright 2015 Apache Cordova
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -200,3 +200,115 @@
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
|
ADDITIONAL LICENSES:
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
bin/node_modules/q
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
Copyright 2009–2012 Kristopher Michael Kowal. All rights reserved.
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to
|
||||||
|
deal in the Software without restriction, including without limitation the
|
||||||
|
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
bin/node_modules/shelljs
|
||||||
|
================================================================================
|
||||||
|
Copyright (c) 2012, Artur Adib <aadib@mozilla.com>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
You may use this project under the terms of the New BSD license as follows:
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of Artur Adib nor the
|
||||||
|
names of the contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
bin/node_modules/nopt
|
||||||
|
================================================================================
|
||||||
|
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
bin/node_modules/which
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
14
NOTICE
@ -1,5 +1,15 @@
|
|||||||
Apache Cordova
|
Apache Cordova
|
||||||
Copyright 2015-2020 The Apache Software Foundation
|
Copyright 2015 The Apache Software Foundation
|
||||||
|
|
||||||
This product includes software developed at
|
This product includes software developed at
|
||||||
The Apache Software Foundation (http://www.apache.org/).
|
The Apache Software Foundation (http://www.apache.org)
|
||||||
|
|
||||||
|
=========================================================================
|
||||||
|
== NOTICE file corresponding to the section 4 d of ==
|
||||||
|
== the Apache License, Version 2.0, ==
|
||||||
|
== in this case for the Android-specific code. ==
|
||||||
|
=========================================================================
|
||||||
|
|
||||||
|
This product includes software developed as part of
|
||||||
|
The Android Open Source Project (http://source.android.com).
|
||||||
|
|
||||||
|
63
README.md
@ -19,53 +19,52 @@
|
|||||||
#
|
#
|
||||||
-->
|
-->
|
||||||
|
|
||||||
# Cordova Android
|
[](https://ci.appveyor.com/project/Humbedooh/cordova-android)
|
||||||
|
[](https://travis-ci.org/apache/cordova-android)
|
||||||
[](https://nodei.co/npm/cordova-android/)
|
|
||||||
|
|
||||||
[](https://github.com/apache/cordova-android/actions?query=branch%3Amaster)
|
|
||||||
[](https://codecov.io/github/apache/cordova-android?branch=master)
|
[](https://codecov.io/github/apache/cordova-android?branch=master)
|
||||||
|
|
||||||
Cordova Android is an Android application library that allows for Cordova-based projects to be built for the Android Platform. Cordova based applications are, at the core, applications written with web technology: HTML, CSS and JavaScript.
|
# Cordova Android
|
||||||
|
|
||||||
[Apache Cordova](https://cordova.apache.org/) is a project of [The Apache Software Foundation (ASF)](https://apache.org/).
|
Cordova Android is an Android application library that allows for Cordova-based
|
||||||
|
projects to be built for the Android Platform. Cordova based applications are,
|
||||||
|
at the core, applications written with web technology: HTML, CSS and JavaScript.
|
||||||
|
|
||||||
## Requirements
|
[Apache Cordova](https://cordova.apache.org) is a project of The Apache Software Foundation (ASF).
|
||||||
|
|
||||||
* Java Development Kit (JDK) 11
|
:warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Android%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
|
||||||
* [Android SDK](https://developer.android.com/)
|
|
||||||
* [Node.js](https://nodejs.org)
|
|
||||||
|
|
||||||
## Create a Cordova project
|
|
||||||
|
|
||||||
Follow the instructions in the [**Create your first Cordova app**](https://cordova.apache.org/docs/en/latest/guide/cli/index.html) section of [Apache Cordova Docs](https://cordova.apache.org/docs/en/latest/)
|
## Requires
|
||||||
|
|
||||||
To use a **shared framework**, for example in development, link the appropriate cordova-android platform folder path:
|
- Java JDK 1.8 or greater
|
||||||
|
- Android SDK [http://developer.android.com](http://developer.android.com)
|
||||||
|
|
||||||
```bash
|
|
||||||
cordova platform add --link /path/to/cordova-android
|
|
||||||
```
|
|
||||||
|
|
||||||
## Updating a Cordova project
|
## Cordova Android Developer Tools
|
||||||
|
|
||||||
When you install a new version of the [`Cordova CLI`](https://www.npmjs.com/package/cordova) that pins a new version of the [`Cordova-Android`](https://www.npmjs.com/package/cordova-android) platform, you can follow these simple upgrade steps within your project:
|
We recommend using the [Cordova command-line tool](https://www.npmjs.com/package/cordova) to create projects and be able to easily install plugins.
|
||||||
|
|
||||||
```bash
|
However, the following scripts can be used instead:
|
||||||
cordova platform rm android
|
|
||||||
cordova platform add android
|
|
||||||
```
|
|
||||||
|
|
||||||
## Debugging in Android Studio
|
./bin/create [path package activity] ... creates the ./example app or a cordova android project
|
||||||
|
./bin/check_reqs ....................... checks that your environment is set up for cordova-android development
|
||||||
|
./bin/update [path] .................... updates an existing cordova-android project to the version of the framework
|
||||||
|
|
||||||
Import project in Android Studio through _File > Open_ and targeting `/path/to/your-cdv-project/platforms/android/`.
|
These commands live in a generated Cordova Android project. Any interactions with the emulator require you to have an AVD defined.
|
||||||
|
|
||||||
## How to Test Repo Development
|
./cordova/clean ........................ cleans the project
|
||||||
|
./cordova/build ........................ calls `clean` then compiles the project
|
||||||
|
./cordova/log ........................ streams device or emulator logs to STDOUT
|
||||||
|
./cordova/run ........................ calls `build` then deploys to a connected Android device. If no Android device is detected, will launch an emulator and deploy to it.
|
||||||
|
./cordova/version ...................... returns the cordova-android version of the current project
|
||||||
|
|
||||||
```bash
|
## Using Android Studio
|
||||||
npm install
|
|
||||||
npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
## Further reading
|
1. Create a project
|
||||||
|
2. Import it via "Non-Android Studio Project"
|
||||||
|
|
||||||
* [Apache Cordova](https://cordova.apache.org/)
|
## Running the Native Tests
|
||||||
|
|
||||||
|
The `test/` directory in this project contains an Android test project that can
|
||||||
|
be used to run different kinds of native tests. Check out the
|
||||||
|
[README contained therein](test/README.md) for more details!
|
||||||
|
489
RELEASENOTES.md
@ -18,494 +18,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
-->
|
-->
|
||||||
## Release Notes for Cordova (Android)
|
## Release Notes for Cordova (Android) ##
|
||||||
|
|
||||||
### 12.0.1 (Aug 23, 2023)
|
|
||||||
|
|
||||||
* [GH-1632](https://github.com/apache/cordova-android/pull/1632) fix(android): `monochrome` checks
|
|
||||||
* [GH-1649](https://github.com/apache/cordova-android/pull/1649) chore: rebuild `package-lock` w/ lint corrections
|
|
||||||
|
|
||||||
### 12.0.0 (May 20, 2023)
|
|
||||||
|
|
||||||
**Breaking:**
|
|
||||||
|
|
||||||
* [GH-1605](https://github.com/apache/cordova-android/pull/1605) fix!: Make `CoreAndroid` plugin instantiate on load
|
|
||||||
* [GH-1539](https://github.com/apache/cordova-android/pull/1539) feat!: bump Gradle 7.6 & AGP 7.4.2
|
|
||||||
* [GH-1571](https://github.com/apache/cordova-android/pull/1571) feat!: bump min SDK to 24
|
|
||||||
* [GH-1538](https://github.com/apache/cordova-android/pull/1538) feat!: bump target sdk & build tools for SDK 33 support
|
|
||||||
* [GH-1540](https://github.com/apache/cordova-android/pull/1540) feat!: bump node engine requirement `>=16.13.0`
|
|
||||||
* [GH-1597](https://github.com/apache/cordova-android/pull/1597) deprecate: `CoreAndroid.getBuildConfigValue`
|
|
||||||
* [GH-1541](https://github.com/apache/cordova-android/pull/1541) dep(npm)!: bump acceptable modules w/ rebuilt `package-lock`
|
|
||||||
* [GH-1566](https://github.com/apache/cordova-android/pull/1566) dep(npm)!: bump `cordova-common@5.0.0`
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
|
|
||||||
* [GH-1602](https://github.com/apache/cordova-android/pull/1602) feat: add `listTarget` api
|
|
||||||
* [GH-1574](https://github.com/apache/cordova-android/pull/1574) feat: add plugin hooks for `WebViewClient.onRenderProcessGone`
|
|
||||||
* [GH-1594](https://github.com/apache/cordova-android/pull/1594) feat: bump default `kotlin` to version 1.7.21
|
|
||||||
* [GH-1550](https://github.com/apache/cordova-android/pull/1550) feat: add `monochrome` app icon support
|
|
||||||
* [GH-1589](https://github.com/apache/cordova-android/pull/1589) feat: `InspectableWebview` preference
|
|
||||||
* [GH-1568](https://github.com/apache/cordova-android/pull/1568) feat: bump `androidx.appcompat.appcompat` 1.6.1
|
|
||||||
* [GH-1567](https://github.com/apache/cordova-android/pull/1567) feat: bump `androidx.webkit.webkit` 1.6.0
|
|
||||||
* [GH-1545](https://github.com/apache/cordova-android/pull/1545) feat: bump `androidx.webkit.webkit` 1.5.0
|
|
||||||
* [GH-1547](https://github.com/apache/cordova-android/pull/1547) feat: bump `com.google.gms.google-services` 4.3.15
|
|
||||||
* [GH-1546](https://github.com/apache/cordova-android/pull/1546) feat: bump `androidx.core.core-splashscreen` 1.0.0
|
|
||||||
* [GH-1544](https://github.com/apache/cordova-android/pull/1544) feat: bump `androidx.appcompat.appcompat` 1.5.1
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1606](https://github.com/apache/cordova-android/pull/1606) fix: Gradle Args parsing
|
|
||||||
* [GH-1575](https://github.com/apache/cordova-android/pull/1575) fix(`BuildHelper`): get package name from `ApplicationInfo`
|
|
||||||
* [GH-1595](https://github.com/apache/cordova-android/pull/1595) fix(test): Native test namespace refactor
|
|
||||||
* [GH-1471](https://github.com/apache/cordova-android/pull/1471) fix: `ANDROID_HOME` is the new default, to check first and give advice
|
|
||||||
* [GH-1573](https://github.com/apache/cordova-android/pull/1573) fix(GH-1432): Default `content` `src` when content tag is missing
|
|
||||||
* [GH-1506](https://github.com/apache/cordova-android/pull/1506) fix: only do fadeout animation if `FadeSplashScreen` is true
|
|
||||||
* [GH-1505](https://github.com/apache/cordova-android/pull/1505) fix: correctly flag API dependency on `AppCompat` for Maven
|
|
||||||
* [GH-1487](https://github.com/apache/cordova-android/pull/1487) fix: Add **Android** prefix to `WindowSplashScreenBrandingImage`
|
|
||||||
* [GH-1489](https://github.com/apache/cordova-android/pull/1489) fix: import type definitions from obsolete `cordova-plugin-splashscreen`
|
|
||||||
|
|
||||||
**Chores, Refactor, Dependencies & CI:**
|
|
||||||
|
|
||||||
* [GH-1493](https://github.com/apache/cordova-android/pull/1493) chore: add `lint:fix` script for fixing lint errors
|
|
||||||
* [GH-1491](https://github.com/apache/cordova-android/pull/1491) chore: Use gradle 7.4.2 distribution url
|
|
||||||
* [GH-1588](https://github.com/apache/cordova-android/pull/1588) refactor: Removed obsolete version code checks
|
|
||||||
* [GH-1492](https://github.com/apache/cordova-android/pull/1492) refactor: replace deprecated `Handler` constructor
|
|
||||||
* [GH-1587](https://github.com/apache/cordova-android/pull/1587) dep: bump npm dependencies
|
|
||||||
* `fs-extra@11.1.1`
|
|
||||||
* `nopt@7.1.0`
|
|
||||||
* `@cordova/eslint-config@5.0.0`
|
|
||||||
* `jasmine@4.6.0`
|
|
||||||
* [GH-1607](https://github.com/apache/cordova-android/pull/1607) ci: Added NodeJS 20.x to the workflow matrix
|
|
||||||
* [GH-1542](https://github.com/apache/cordova-android/pull/1542) ci(workflow): update `codecov/codecov-action@v3`
|
|
||||||
* [GH-1532](https://github.com/apache/cordova-android/pull/1532) ci: update `codecov/codecov-action` reporting format
|
|
||||||
|
|
||||||
### 11.0.0 (Jul 04, 2022)
|
|
||||||
|
|
||||||
**Breaking:**
|
|
||||||
|
|
||||||
* [GH-1441](https://github.com/apache/cordova-android/pull/1441) feat!: **Android** 12 splash screen
|
|
||||||
* [GH-1427](https://github.com/apache/cordova-android/pull/1427) feat!: API 32 support
|
|
||||||
* [GH-1410](https://github.com/apache/cordova-android/pull/1410) feat!: API 31 support
|
|
||||||
* [GH-1444](https://github.com/apache/cordova-android/pull/1444) fix!: set & use `ANDROID_HOME` as default
|
|
||||||
* [GH-1411](https://github.com/apache/cordova-android/pull/1411) chore!: Drop Node 12 support
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
|
|
||||||
* [GH-1448](https://github.com/apache/cordova-android/pull/1448) feat: Update `androidx.appcompat` version
|
|
||||||
* [GH-1446](https://github.com/apache/cordova-android/pull/1446) feat: Update gradle plugin version
|
|
||||||
* [GH-1447](https://github.com/apache/cordova-android/pull/1447) feat: Update google services pluging
|
|
||||||
* [GH-1431](https://github.com/apache/cordova-android/pull/1431) feat: support custom `compileSdk` setting
|
|
||||||
* [GH-1311](https://github.com/apache/cordova-android/pull/1311) feat: added support for BoM imports
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1455](https://github.com/apache/cordova-android/pull/1455) fix(`prepare`): `destFile` path separator
|
|
||||||
* [GH-1453](https://github.com/apache/cordova-android/pull/1453) fix: support installing platfrom from local git checkout
|
|
||||||
* [GH-1449](https://github.com/apache/cordova-android/pull/1449) fix: accept file cookies only if `AndroidInsecureFileModeEnabled`
|
|
||||||
* [GH-1443](https://github.com/apache/cordova-android/pull/1443) fix: force `hostname` to lowercase
|
|
||||||
* [GH-1434](https://github.com/apache/cordova-android/pull/1434) fix: restore `checkReqs` in `prepare.js`
|
|
||||||
* [GH-1154](https://github.com/apache/cordova-android/pull/1154) fix: move `MainActivity.java` to folder that tracks the app package name (widget id)
|
|
||||||
|
|
||||||
**Chores, Dependencies & CI:**
|
|
||||||
|
|
||||||
* [GH-1451](https://github.com/apache/cordova-android/pull/1451) chore: display warning on deprecated `<splash>` tag usage
|
|
||||||
* [GH-1430](https://github.com/apache/cordova-android/pull/1430) chore: remove unneeded deprecated annotation
|
|
||||||
* [GH-1421](https://github.com/apache/cordova-android/pull/1421) chore(npm): bump `@cordova/eslint-config@^4.0.0`
|
|
||||||
* [GH-1420](https://github.com/apache/cordova-android/pull/1420) chore(npm): bump dependencies
|
|
||||||
* [GH-1452](https://github.com/apache/cordova-android/pull/1452) dep: bump `jasmine@4.2.1` w/ `package-lock` rebuild
|
|
||||||
* [GH-1439](https://github.com/apache/cordova-android/pull/1439) ci: update github action workflow
|
|
||||||
* [GH-1424](https://github.com/apache/cordova-android/pull/1424) ci: Added Node 18 to test matrix
|
|
||||||
|
|
||||||
### 10.1.2 (Apr 11, 2022)
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1372](https://github.com/apache/cordova-android/pull/1372) fix(`AndroidManifest`): explicitly define the `activity` attribute `android:exported`
|
|
||||||
* [GH-1406](https://github.com/apache/cordova-android/pull/1406) fix: detect `JAVA_HOME` with Java 11
|
|
||||||
* [GH-1401](https://github.com/apache/cordova-android/pull/1401) fix(GH-1391): Reword minimum build tools version to make it more clear what is actually required.
|
|
||||||
* [GH-1384](https://github.com/apache/cordova-android/pull/1384) fix: escape `strings.xml` app name
|
|
||||||
|
|
||||||
**Chores:**
|
|
||||||
|
|
||||||
* [GH-1413](https://github.com/apache/cordova-android/pull/1413) chore: update `package-lock` to satisfy `npm audit`
|
|
||||||
* [GH-1348](https://github.com/apache/cordova-android/pull/1348) chore: `npmrc`
|
|
||||||
|
|
||||||
### 10.1.1 (Sep 13, 2021)
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1349](https://github.com/apache/cordova-android/pull/1349) fix(`PluginManager`): `AllowNavigation` default policy to handle scheme & hostname
|
|
||||||
* [GH-1342](https://github.com/apache/cordova-android/pull/1342) fix(`AllowListPlugin`): Safely handle default allow navigation policy in allow request
|
|
||||||
* [GH-1332](https://github.com/apache/cordova-android/pull/1332) fix(`PluginManager`): `AllowBridgeAccess` default policy to handle scheme & hostname
|
|
||||||
|
|
||||||
### 10.1.0 (Aug 13, 2021)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
|
|
||||||
* [GH-1213](https://github.com/apache/cordova-android/pull/1213) feat: unify `create` default values & stop project name transform
|
|
||||||
* [GH-1306](https://github.com/apache/cordova-android/pull/1306) feat: bump `ANDROIDX_APP_COMPAT@1.3.1`
|
|
||||||
* [GH-1303](https://github.com/apache/cordova-android/pull/1303) feat: bump `Google Services Gradle Plugin@4.3.8`
|
|
||||||
* [GH-1302](https://github.com/apache/cordova-android/pull/1302) feat: bump `kotlin@1.5.21`
|
|
||||||
* [GH-1298](https://github.com/apache/cordova-android/pull/1298) feat: support `http` w/ `content` `src` fix
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1214](https://github.com/apache/cordova-android/pull/1214) fix: display project name in Android Studio
|
|
||||||
* [GH-1300](https://github.com/apache/cordova-android/pull/1300) fix: fall back to project root `repositories.gradle`
|
|
||||||
|
|
||||||
**Docs:**
|
|
||||||
|
|
||||||
* [GH-1308](https://github.com/apache/cordova-android/pull/1308) doc: update `README` about development & testing
|
|
||||||
|
|
||||||
### 10.0.1 (Jul 27, 2021)
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1295](https://github.com/apache/cordova-android/pull/1295) fix: `maven-publish` setup
|
|
||||||
* [GH-1293](https://github.com/apache/cordova-android/pull/1293) fix: `gradle` build tools config
|
|
||||||
* [GH-1294](https://github.com/apache/cordova-android/pull/1294) fix: automatic latest build tools finding
|
|
||||||
* [GH-1287](https://github.com/apache/cordova-android/pull/1287) fix: Google Services Gradle Plugin version check failure
|
|
||||||
|
|
||||||
**Chores:**
|
|
||||||
|
|
||||||
* [GH-1291](https://github.com/apache/cordova-android/pull/1291) chore: add missing release notes
|
|
||||||
* [GH-1286](https://github.com/apache/cordova-android/pull/1286) chore: update `README` requirements
|
|
||||||
|
|
||||||
### 10.0.0 (Jul 17, 2021)
|
|
||||||
|
|
||||||
**Breaking:**
|
|
||||||
|
|
||||||
* [GH-1052](https://github.com/apache/cordova-android/pull/1052) feat!: only support `AndroidX`
|
|
||||||
* [GH-1137](https://github.com/apache/cordova-android/pull/1137) feat!: implement `WebViewAssetLoader`
|
|
||||||
* [GH-1268](https://github.com/apache/cordova-android/pull/1268) feat!: release build defaults to `aab` package type
|
|
||||||
* [GH-1182](https://github.com/apache/cordova-android/pull/1182) feat!: bump `target sdk@30` w/ `build-tool@30.0.3`
|
|
||||||
* [GH-1257](https://github.com/apache/cordova-android/pull/1257) feat!: upgrade `gradle@7.1.1`
|
|
||||||
* [GH-1197](https://github.com/apache/cordova-android/pull/1197) feat!: upgrade `gradle@6.8.3`
|
|
||||||
* [GH-1256](https://github.com/apache/cordova-android/pull/1256) feat!: upgrade `kotlin@1.5.20`
|
|
||||||
* [GH-1204](https://github.com/apache/cordova-android/pull/1204) feat!: upgrade `kotlin@1.4.32`
|
|
||||||
* [GH-1200](https://github.com/apache/cordova-android/pull/1200) feat!: upgrade `kotlin@1.4.31`
|
|
||||||
* [GH-1255](https://github.com/apache/cordova-android/pull/1255) feat!: upgrade `android-gradle-plugin@4.2.2`
|
|
||||||
* [GH-1232](https://github.com/apache/cordova-android/pull/1232) feat!: upgrade `android-gradle-plugin@4.2.1`
|
|
||||||
* [GH-1198](https://github.com/apache/cordova-android/pull/1198) feat!: upgrade `android-gradle-plugin@4.1.3`
|
|
||||||
* [GH-1199](https://github.com/apache/cordova-android/pull/1199) feat!: upgrade `Google Services Gradle Plugin@4.3.5`
|
|
||||||
* [GH-1262](https://github.com/apache/cordova-android/pull/1262) feat!: bump `appcompat@1.3.0`
|
|
||||||
* [GH-1258](https://github.com/apache/cordova-android/pull/1258) feat!: bump `android.webkit@1.4.0`
|
|
||||||
* [GH-1252](https://github.com/apache/cordova-android/pull/1252) feat!: drop abandoned `com.github.dcendents:android-maven-gradle-plugin`
|
|
||||||
* [GH-1212](https://github.com/apache/cordova-android/pull/1212) feat!: unify & fix gradle library/tooling overrides
|
|
||||||
* [GH-1138](https://github.com/apache/cordova-android/pull/1138) feat(allow-list)!: integrate and refactor core plugin
|
|
||||||
* [GH-1201](https://github.com/apache/cordova-android/pull/1201) feat!: upgrade jfrog `gradle-bintray-plugin@1.8.5`
|
|
||||||
* [GH-1279](https://github.com/apache/cordova-android/pull/1279) chore!: bump all dependencies
|
|
||||||
* [GH-1278](https://github.com/apache/cordova-android/pull/1278) chore!: drop `node` 10 support
|
|
||||||
* [GH-1205](https://github.com/apache/cordova-android/pull/1205) chore! (`npm`): update all dependencies
|
|
||||||
* [GH-1274](https://github.com/apache/cordova-android/pull/1274) cleanup!: remove deprecated settings & add todo comments
|
|
||||||
* [GH-1048](https://github.com/apache/cordova-android/pull/1048) cleanup!: remove `keystore` password prompt
|
|
||||||
* [GH-1251](https://github.com/apache/cordova-android/pull/1251) cleanup!: drop `jcenter` & update dependencies
|
|
||||||
* [GH-1269](https://github.com/apache/cordova-android/pull/1269) refactor!: do not copy JS lib to platform project
|
|
||||||
* [GH-1270](https://github.com/apache/cordova-android/pull/1270) refactor(Api)!: use version from `package.json`
|
|
||||||
* [GH-1266](https://github.com/apache/cordova-android/pull/1266) refactor(run)!: `run` method
|
|
||||||
* [GH-1083](https://github.com/apache/cordova-android/pull/1083) refactor!: drop support for `android` SDK tool
|
|
||||||
* [GH-1100](https://github.com/apache/cordova-android/pull/1100) refactor!: remove most platform binaries
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
|
|
||||||
* [GH-1241](https://github.com/apache/cordova-android/pull/1241) feat: remove `java` 1.8 version check
|
|
||||||
* [GH-1254](https://github.com/apache/cordova-android/pull/1254) feat: support `webkit` version override
|
|
||||||
* [GH-1229](https://github.com/apache/cordova-android/pull/1229) feat: `CORDOVA_JAVA_HOME` env variable
|
|
||||||
* [GH-1222](https://github.com/apache/cordova-android/pull/1222) feat: add backwards compatibility mode for `WebViewAssetLoader`
|
|
||||||
* [GH-1166](https://github.com/apache/cordova-android/pull/1166) feat: overload `PluginEntry` constructor to set onload property
|
|
||||||
* [GH-1208](https://github.com/apache/cordova-android/pull/1208) feat: allow `appcompat` version to be configurable
|
|
||||||
* [GH-1047](https://github.com/apache/cordova-android/pull/1047) feat: Deprecated `onRequestPermissionResult` in favour for `onRequestPermissionsResult` for consistency
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1283](https://github.com/apache/cordova-android/pull/1283) fix: add missing apache-license header to `getASPath.bat`
|
|
||||||
* [GH-1275](https://github.com/apache/cordova-android/pull/1275) fix: add `WebViewAssetloader` to default allow list
|
|
||||||
* [GH-1216](https://github.com/apache/cordova-android/pull/1216) fix: request focus after custom view hided
|
|
||||||
* [GH-1264](https://github.com/apache/cordova-android/pull/1264) fix: missing `super.onRequestPermissionsResult` error (`MissingSuperCall`)
|
|
||||||
* [GH-563](https://github.com/apache/cordova-android/pull/563) fix(build): support tilde expansion on Windows
|
|
||||||
* [GH-1220](https://github.com/apache/cordova-android/pull/1220) fix(`requirements` check): use regex to get java version from javac output
|
|
||||||
* [GH-1227](https://github.com/apache/cordova-android/pull/1227) fix(prepare): delete splash screens if none are used
|
|
||||||
* [GH-1228](https://github.com/apache/cordova-android/pull/1228) fix: java checks
|
|
||||||
* [GH-1276](https://github.com/apache/cordova-android/pull/1276) fix: remove forced default `gradle.daemon` setting
|
|
||||||
|
|
||||||
**Refactors:**
|
|
||||||
|
|
||||||
* [GH-1265](https://github.com/apache/cordova-android/pull/1265) refactor: do not infer project root from script location
|
|
||||||
* [GH-1267](https://github.com/apache/cordova-android/pull/1267) refactor: use target SDK of built APK to determine best emulator
|
|
||||||
* [GH-1253](https://github.com/apache/cordova-android/pull/1253) refactor: `gradle` cleanup
|
|
||||||
* [GH-1260](https://github.com/apache/cordova-android/pull/1260) refactor(`check_reqs`): drop `originalError` param from `check_android_target`
|
|
||||||
* [GH-1246](https://github.com/apache/cordova-android/pull/1246) refactor(`env/java`): improve tests and implementation
|
|
||||||
|
|
||||||
**Chores & Cleanup:**
|
|
||||||
|
|
||||||
* [GH-1273](https://github.com/apache/cordova-android/pull/1273) chore: remove old `VERSION` file
|
|
||||||
* [GH-1272](https://github.com/apache/cordova-android/pull/1272) cleanup: delete old ANT & Eclipse files
|
|
||||||
* [GH-1141](https://github.com/apache/cordova-android/pull/1141) cleanup: remove app cache settings
|
|
||||||
|
|
||||||
**CI, Build & Testing:**
|
|
||||||
|
|
||||||
* [GH-1218](https://github.com/apache/cordova-android/pull/1218) ci: Add `Node16` to CI matrix
|
|
||||||
* [GH-1271](https://github.com/apache/cordova-android/pull/1271) build: build `cordova.js` during npm prepare
|
|
||||||
* [GH-1207](https://github.com/apache/cordova-android/pull/1207) test(`AndroidManifest`): update theme to `Theme.AppCompat.NoActionBar`
|
|
||||||
* [GH-1263](https://github.com/apache/cordova-android/pull/1263) test(`check_reqs`): do not hardcode `DEFAULT_TARGET_API`
|
|
||||||
* [GH-1259](https://github.com/apache/cordova-android/pull/1259) test(`prepare`): factor out common vars
|
|
||||||
|
|
||||||
### 9.1.0 (Apr 09, 2021)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
|
|
||||||
* [GH-1104](https://github.com/apache/cordova-android/pull/1104) feat: support `gzip` encoding requests & use `GZIPInputStream`
|
|
||||||
* [GH-1167](https://github.com/apache/cordova-android/pull/1167) feat: handle `intent://` scheme links with `browser_fallback_url` param
|
|
||||||
* [GH-1179](https://github.com/apache/cordova-android/pull/1179) feat: add `repositories` support
|
|
||||||
* [GH-1173](https://github.com/apache/cordova-android/pull/1173) feat(android-studio): display app name as project name
|
|
||||||
* [GH-1113](https://github.com/apache/cordova-android/pull/1113) feat: `webp` support for splashscreen
|
|
||||||
* [GH-1125](https://github.com/apache/cordova-android/pull/1125) feat(Adb): list `devices` _and_ `emulators` in one go
|
|
||||||
|
|
||||||
**Fixes:**
|
|
||||||
|
|
||||||
* [GH-1186](https://github.com/apache/cordova-android/pull/1186) fix: copy `repositories.gradle` to project on create
|
|
||||||
* [GH-1184](https://github.com/apache/cordova-android/pull/1184) fix: unit-test failure
|
|
||||||
* [GH-733](https://github.com/apache/cordova-android/pull/733) fix(splashscreen): nav & title bar showing in fullscreen mode
|
|
||||||
* [GH-1157](https://github.com/apache/cordova-android/pull/1157) fix: restore key event handlers when DOM element is fullscreen
|
|
||||||
* [GH-1073](https://github.com/apache/cordova-android/pull/1073) fix(android): Avoid Crash Report: ConcurrentModificationException
|
|
||||||
* [GH-1148](https://github.com/apache/cordova-android/pull/1148) fix: add not null checks to prevent running on destroyed activity
|
|
||||||
* [GH-1091](https://github.com/apache/cordova-android/pull/1091) fix: concurrent modification exception (#924)
|
|
||||||
* [GH-1153](https://github.com/apache/cordova-android/pull/1153) fix: optional arch parameter
|
|
||||||
* [GH-1136](https://github.com/apache/cordova-android/pull/1136) fix(prepare): `mapImageResources` always returning `[]`
|
|
||||||
* [GH-1111](https://github.com/apache/cordova-android/pull/1111) fix(android): allow file access for existing behavior
|
|
||||||
* [GH-1045](https://github.com/apache/cordova-android/pull/1045) fix: Reflect minimum required NodeJS
|
|
||||||
* [GH-1084](https://github.com/apache/cordova-android/pull/1084) fix(prepare): fix pattern used to collect image resources
|
|
||||||
* [GH-1014](https://github.com/apache/cordova-android/pull/1014) fix(`pluginHandlers`): properly check if path is inside another
|
|
||||||
* [GH-1018](https://github.com/apache/cordova-android/pull/1018) fix: gradle ignore properties
|
|
||||||
* [GH-1185](https://github.com/apache/cordova-android/pull/1185) fix(regression): Cannot read version of undefined caused by Java refactor
|
|
||||||
* [GH-1117](https://github.com/apache/cordova-android/pull/1117) fix: allow changing min sdk version
|
|
||||||
|
|
||||||
**Refactors:**
|
|
||||||
|
|
||||||
* [GH-1101](https://github.com/apache/cordova-android/pull/1101) refactor: unify target resolution for devices & emulators
|
|
||||||
* [GH-1130](https://github.com/apache/cordova-android/pull/1130) refactor: java checks
|
|
||||||
* [GH-1099](https://github.com/apache/cordova-android/pull/1099) refactor(`ProjectBuilder`): clean up output file collection code
|
|
||||||
* [GH-1123](https://github.com/apache/cordova-android/pull/1123) refactor: unify installation on devices & emulators
|
|
||||||
* [GH-1102](https://github.com/apache/cordova-android/pull/1102) refactor(`check_reqs`): cleanup default Java location detection on **Windows**
|
|
||||||
* [GH-1103](https://github.com/apache/cordova-android/pull/1103) refactor: do not kill adb on UNIX-like systems
|
|
||||||
* [GH-1086](https://github.com/apache/cordova-android/pull/1086) refactor(retry): simplify retryPromise using modern JS
|
|
||||||
* [GH-1085](https://github.com/apache/cordova-android/pull/1085) refactor(utils): reduce number of utils
|
|
||||||
* [GH-1046](https://github.com/apache/cordova-android/pull/1046) refactor: Stop suppressing un-needed TruelyRandom lints
|
|
||||||
* [GH-1016](https://github.com/apache/cordova-android/pull/1016) refactor: save `ProjectBuilder` instance in Api instance
|
|
||||||
* [GH-1108](https://github.com/apache/cordova-android/pull/1108) refactor: remove copied Adb.install from `emulator.install`
|
|
||||||
|
|
||||||
**Chores:**
|
|
||||||
|
|
||||||
* [GH-1196](https://github.com/apache/cordova-android/pull/1196) chore: add missing header license
|
|
||||||
* chore(asf): Update GitHub repo metadata
|
|
||||||
* [GH-1183](https://github.com/apache/cordova-android/pull/1183) chore: rebuilt package-lock
|
|
||||||
* [GH-1015](https://github.com/apache/cordova-android/pull/1015) chore: remove unnecessary stuff
|
|
||||||
* [GH-1081](https://github.com/apache/cordova-android/pull/1081) chore(pkg): remove deprecated `no-op` field `"engineStrict"`
|
|
||||||
* [GH-1019](https://github.com/apache/cordova-android/pull/1019) chore: remove unused `emulator.create_image` and its dependencies
|
|
||||||
|
|
||||||
**Tests & CI:**
|
|
||||||
|
|
||||||
* [GH-1017](https://github.com/apache/cordova-android/pull/1017) test(java): fix, improve and move clean script
|
|
||||||
* [GH-1012](https://github.com/apache/cordova-android/pull/1012) test: fix missing stack traces in jasmine output
|
|
||||||
* [GH-1013](https://github.com/apache/cordova-android/pull/1013) test(`pluginHandlers/common`): better setup & teardown
|
|
||||||
* [GH-1094](https://github.com/apache/cordova-android/pull/1094) test: fix unit test failures for certain random orders
|
|
||||||
* [GH-1094](https://github.com/apache/cordova-android/pull/1094) test: ensure single top-level describe block in test file
|
|
||||||
* [GH-1129](https://github.com/apache/cordova-android/pull/1129) test(java): remove duplicate code in `BackButtonMultipageTest`
|
|
||||||
* [GH-975](https://github.com/apache/cordova-android/pull/975) ci: Added Node 14.x
|
|
||||||
|
|
||||||
### 9.0.0 (Jun 23, 2020)
|
|
||||||
|
|
||||||
* [GH-1005](https://github.com/apache/cordova-android/pull/1005) chore: set AndroidX off by default
|
|
||||||
* [GH-971](https://github.com/apache/cordova-android/pull/971) fix: Accept multiple mime types on file input
|
|
||||||
* [GH-1001](https://github.com/apache/cordova-android/pull/1001) fix: support both adaptive and standard icons at the same time
|
|
||||||
* [GH-985](https://github.com/apache/cordova-android/pull/985) fix: Plugin install fails when preview sdk is installed
|
|
||||||
* [GH-994](https://github.com/apache/cordova-android/pull/994) chore: cleanup yaml files
|
|
||||||
* [GH-999](https://github.com/apache/cordova-android/pull/999) chore: remove trailing spaces from Java sources
|
|
||||||
* [GH-992](https://github.com/apache/cordova-android/pull/992) chore: update some dependencies
|
|
||||||
* [GH-998](https://github.com/apache/cordova-android/pull/998) chore: remove trailing spaces from framework build files
|
|
||||||
* [GH-997](https://github.com/apache/cordova-android/pull/997) chore: remove trailing spaces from project template
|
|
||||||
* [GH-996](https://github.com/apache/cordova-android/pull/996) chore: remove trailing spaces from bat files
|
|
||||||
* [GH-995](https://github.com/apache/cordova-android/pull/995) remove trailing spaces from markdown files
|
|
||||||
* [GH-993](https://github.com/apache/cordova-android/pull/993) chore: update `devDependencies`
|
|
||||||
* [GH-987](https://github.com/apache/cordova-android/pull/987) breaking: reduce combined response cutoff to 16 MB
|
|
||||||
* [GH-988](https://github.com/apache/cordova-android/pull/988) major: Gradle 6.5 & **Android** Gradle plugin 4.0.0 updates
|
|
||||||
* [GH-990](https://github.com/apache/cordova-android/pull/990) chore: remove trailing spaces from `app/build.gradle`
|
|
||||||
* [GH-989](https://github.com/apache/cordova-android/pull/989) breaking: remove `legacy/build.gradle` from template
|
|
||||||
* [GH-978](https://github.com/apache/cordova-android/pull/978) fix: `wait_for_boot` waiting forever
|
|
||||||
* [GH-965](https://github.com/apache/cordova-android/pull/965) fix: Increased `detectArchitecture()` timeout
|
|
||||||
* [GH-962](https://github.com/apache/cordova-android/pull/962) breaking: Bump **Android** gradle plugin to 3.6.0
|
|
||||||
* [GH-948](https://github.com/apache/cordova-android/pull/948) feature: JVM Args flag
|
|
||||||
* [GH-951](https://github.com/apache/cordova-android/pull/951) fix: `ANDROID_SDK_ROOT` variable
|
|
||||||
* [GH-959](https://github.com/apache/cordova-android/pull/959) test: synced AndroidX gradle versions to the same version as the **Android** test
|
|
||||||
* [GH-960](https://github.com/apache/cordova-android/pull/960) feat: `com.android.tools.build:gradle:3.5.3`
|
|
||||||
* [GH-956](https://github.com/apache/cordova-android/pull/956) chore(npm): add `package-lock.json`
|
|
||||||
* [GH-958](https://github.com/apache/cordova-android/pull/958) chore(npm): add ignore list
|
|
||||||
* [GH-957](https://github.com/apache/cordova-android/pull/957) chore: various cleanup
|
|
||||||
* [GH-955](https://github.com/apache/cordova-android/pull/955) chore(eslint): bump package & apply eslint fix
|
|
||||||
* [GH-954](https://github.com/apache/cordova-android/pull/954) breaking(npm): bump packages
|
|
||||||
* [GH-953](https://github.com/apache/cordova-android/pull/953) chore(npm): use short notation in `package.json`
|
|
||||||
* [GH-823](https://github.com/apache/cordova-android/pull/823) fix: prevent exit fullscreen mode from closing application
|
|
||||||
* [GH-950](https://github.com/apache/cordova-android/pull/950) fix: removed redundent logcat print
|
|
||||||
* [GH-915](https://github.com/apache/cordova-android/pull/915) breaking: bump minSdkVersion to 22 and drop pre-Lollipop specific code
|
|
||||||
* [GH-941](https://github.com/apache/cordova-android/pull/941) fix: GH-873 App bundle builds to obey command-line arguments
|
|
||||||
* [GH-940](https://github.com/apache/cordova-android/pull/940) ci: drop travis & move codecov to gh-actions
|
|
||||||
* [GH-929](https://github.com/apache/cordova-android/pull/929) chore: updated `README` to reflect what **Android** requires more accurately, which is Java 8, not anything less, not anything greater. Java 1.8.x is required.
|
|
||||||
* [GH-937](https://github.com/apache/cordova-android/pull/937) fix: GH-935 replaced `compare-func` with native sort method
|
|
||||||
* [GH-939](https://github.com/apache/cordova-android/pull/939) fix: test failure with shebang interpreter in `rewired` files
|
|
||||||
* [GH-911](https://github.com/apache/cordova-android/pull/911) refactor: use es6 class
|
|
||||||
* [GH-910](https://github.com/apache/cordova-android/pull/910) refactor (eslint): use `cordova-eslint`
|
|
||||||
* [GH-909](https://github.com/apache/cordova-android/pull/909) chore: remove appveyor residual
|
|
||||||
* [GH-895](https://github.com/apache/cordova-android/pull/895) feat: add github actions
|
|
||||||
* [GH-842](https://github.com/apache/cordova-android/pull/842) refactor: remove `shelljs` dependency
|
|
||||||
* [GH-896](https://github.com/apache/cordova-android/pull/896) feat: add Kotlin support
|
|
||||||
* [GH-901](https://github.com/apache/cordova-android/pull/901) feat: add AndroidX support
|
|
||||||
* [GH-849](https://github.com/apache/cordova-android/pull/849) fix: cordova requirements consider the `android-targetSdkVersion`
|
|
||||||
* [GH-904](https://github.com/apache/cordova-android/pull/904) fix (adb): shell to return expected stdout
|
|
||||||
* [GH-792](https://github.com/apache/cordova-android/pull/792) feat: upgrade `gradle` to 6.1 & gradle build tools to 3.5.3
|
|
||||||
* [GH-902](https://github.com/apache/cordova-android/pull/902) chore: remove `.project` file & add `.settings` to `gitignore`
|
|
||||||
* [GH-900](https://github.com/apache/cordova-android/pull/900) refactor: simplify `doFindLatestInstalledBuildTools`
|
|
||||||
* [GH-751](https://github.com/apache/cordova-android/pull/751) feat: use Java package name for loading `BuildConfig`
|
|
||||||
* [GH-898](https://github.com/apache/cordova-android/pull/898) chore: rename gradle plugin google services `preference` options
|
|
||||||
* [GH-893](https://github.com/apache/cordova-android/pull/893) feat: add Google Services support
|
|
||||||
* [GH-709](https://github.com/apache/cordova-android/pull/709) feat: add `version-compare` library to compare `build-tools` versions properly.
|
|
||||||
* [GH-831](https://github.com/apache/cordova-android/pull/831) chore: ignore auto-generated eclipse buildship files
|
|
||||||
* [GH-848](https://github.com/apache/cordova-android/pull/848) breaking: increased default target sdk to 29
|
|
||||||
* [GH-859](https://github.com/apache/cordova-android/pull/859) breaking: removed unnecessary project name restriction
|
|
||||||
* [GH-833](https://github.com/apache/cordova-android/pull/833) chore: drop `q` module
|
|
||||||
* [GH-862](https://github.com/apache/cordova-android/pull/862) chore: replace `superspawn` & `child_process` with `execa`
|
|
||||||
* [GH-860](https://github.com/apache/cordova-android/pull/860) feat: don't filter gradle's stderr anymore
|
|
||||||
* [GH-832](https://github.com/apache/cordova-android/pull/832) chore: drop node 6 and 8 support
|
|
||||||
* [GH-890](https://github.com/apache/cordova-android/pull/890) chore: bump version to 9.0.0-dev
|
|
||||||
* [GH-697](https://github.com/apache/cordova-android/pull/697) chore: optimization code
|
|
||||||
* [GH-863](https://github.com/apache/cordova-android/pull/863) chore: removed comment that serves no purpose
|
|
||||||
* [GH-861](https://github.com/apache/cordova-android/pull/861) chore: update `jasmine` to 3.5.0
|
|
||||||
* [GH-858](https://github.com/apache/cordova-android/pull/858) chore: modernize our one E2E test
|
|
||||||
* [GH-854](https://github.com/apache/cordova-android/pull/854) chore: ensure to lint as many files as possible
|
|
||||||
|
|
||||||
### 8.1.0 (Sep 11, 2019)
|
|
||||||
|
|
||||||
* [GH-827](https://github.com/apache/cordova-android/pull/827) chore: bump dependencies for release 8.1.0
|
|
||||||
* [GH-651](https://github.com/apache/cordova-android/pull/651) feat: added multiple selection for filepicker
|
|
||||||
* [GH-672](https://github.com/apache/cordova-android/pull/672) chore: compress files in /res with tinypng.com
|
|
||||||
* [GH-815](https://github.com/apache/cordova-android/pull/815) fix: `clean` command
|
|
||||||
* [GH-750](https://github.com/apache/cordova-android/pull/750) Don't request focus explicitly if not needed
|
|
||||||
* [GH-800](https://github.com/apache/cordova-android/pull/800) [GH-799](https://github.com/apache/cordova-android/pull/799) (android) Stop webview from restarting when activity resizes
|
|
||||||
* [GH-764](https://github.com/apache/cordova-android/pull/764) feat: Build app bundles (.aab files)
|
|
||||||
* [GH-788](https://github.com/apache/cordova-android/pull/788) Simplify `apkSorter` using `compare-func` package
|
|
||||||
* [GH-787](https://github.com/apache/cordova-android/pull/787) Simplify and fix promise handling in specs
|
|
||||||
* [GH-784](https://github.com/apache/cordova-android/pull/784) Properly handle promise in create script
|
|
||||||
* [GH-783](https://github.com/apache/cordova-android/pull/783) Do not clobber process properties with test mocks
|
|
||||||
* [GH-782](https://github.com/apache/cordova-android/pull/782) Do not clobber `console.log` to spy on it
|
|
||||||
* [GH-724](https://github.com/apache/cordova-android/pull/724) Add Node.js 12 to CI Services
|
|
||||||
* [GH-777](https://github.com/apache/cordova-android/pull/777) ci(travis): set `dist: trusty` in `.travis.yml`
|
|
||||||
* [GH-779](https://github.com/apache/cordova-android/pull/779) Consistent order from `ProjectBuilder.apkSorter`
|
|
||||||
* [GH-778](https://github.com/apache/cordova-android/pull/778) test: use verbose spec reporter
|
|
||||||
* [GH-774](https://github.com/apache/cordova-android/pull/774) `rewire` workaround for NodeJS 12
|
|
||||||
* [GH-772](https://github.com/apache/cordova-android/pull/772) `nyc@14` update in devDependencies
|
|
||||||
* [GH-765](https://github.com/apache/cordova-android/pull/765) ci(travis): Fix **Android** SDK
|
|
||||||
* [GH-713](https://github.com/apache/cordova-android/pull/713) Do not explicitly require modules from project directory
|
|
||||||
* [GH-676](https://github.com/apache/cordova-android/pull/676) Added allprojects repositories for Framework Release Builds
|
|
||||||
* [GH-699](https://github.com/apache/cordova-android/pull/699) Improve Gradle Build Arguments
|
|
||||||
* [GH-710](https://github.com/apache/cordova-android/pull/710) Fix deprecation warning in `SystemCookieManager`
|
|
||||||
* [GH-691](https://github.com/apache/cordova-android/pull/691) [GH-690](https://github.com/apache/cordova-android/pull/690): Run `prepare` with the correct `ConfigParser`
|
|
||||||
* [GH-673](https://github.com/apache/cordova-android/pull/673) Updated `Android_HOME` Test to Follow [GH-656](https://github.com/apache/cordova-android/pull/656) Change
|
|
||||||
|
|
||||||
### 8.0.0 (Feb 13, 2019)
|
|
||||||
* [GH-669](https://github.com/apache/cordova-android/pull/669) Added Missing License Headers
|
|
||||||
* [GH-655](https://github.com/apache/cordova-android/pull/655) Use custom Gradle properties to read minSdkVersion value from `config.xml`
|
|
||||||
* [GH-656](https://github.com/apache/cordova-android/pull/656) Quick fix to support **Android**_SDK_ROOT
|
|
||||||
* [GH-632](https://github.com/apache/cordova-android/pull/632) Ignore more Gradle build artifacts in **Android** project
|
|
||||||
* [GH-642](https://github.com/apache/cordova-android/pull/642) **Android** tools 3.3 & **Gradle** 4.10.3 update
|
|
||||||
* [GH-654](https://github.com/apache/cordova-android/pull/654) Quick updates to top-level `project.properties`
|
|
||||||
* [GH-635](https://github.com/apache/cordova-android/pull/635) Ignore **Android** Studio `.idea` files in project
|
|
||||||
* [GH-624](https://github.com/apache/cordova-android/pull/624) Add missing log to Java version check
|
|
||||||
* [GH-630](https://github.com/apache/cordova-android/pull/630) Update `emulator.js` to fix issue [GH-608](https://github.com/apache/cordova-android/pull/608)
|
|
||||||
* [GH-626](https://github.com/apache/cordova-android/pull/626) Added `package-lock.json` to `.gitignore`
|
|
||||||
* [GH-620](https://github.com/apache/cordova-android/pull/620) Fix requirements error messages for JDK 8
|
|
||||||
* [GH-619](https://github.com/apache/cordova-android/pull/619) javac error message fixes in requirements check
|
|
||||||
* [GH-612](https://github.com/apache/cordova-android/pull/612) Android Platform Release Preparation (Cordova 9)
|
|
||||||
* [GH-607](https://github.com/apache/cordova-android/pull/607) Copy `node_modules` if the directory exists
|
|
||||||
* [GH-582](https://github.com/apache/cordova-android/pull/582) Improve Test `README`
|
|
||||||
* [GH-589](https://github.com/apache/cordova-android/pull/589) Rewrite install dir resolution for legacy plugins
|
|
||||||
* [GH-572](https://github.com/apache/cordova-android/pull/572) Resolve issue with plugin `target-dir="app*"` subdirs
|
|
||||||
* [GH-567](https://github.com/apache/cordova-android/pull/567) Output current package name if package name can't be validated
|
|
||||||
* [GH-507](https://github.com/apache/cordova-android/pull/507) Gradle Updates
|
|
||||||
* [GH-559](https://github.com/apache/cordova-android/pull/559) Eslint ignore version file
|
|
||||||
* [GH-550](https://github.com/apache/cordova-android/pull/550) Fix for old plugins with non-Java sources
|
|
||||||
* [GH-558](https://github.com/apache/cordova-android/pull/558) Update `cordova.js` from `cordova-js@4.2.3`
|
|
||||||
* [GH-553](https://github.com/apache/cordova-android/pull/553) Check for `build-extras.gradle` in the app-parent directory
|
|
||||||
* [GH-551](https://github.com/apache/cordova-android/pull/551) Add missing cast for `cdvMinSdkVersion`
|
|
||||||
* [GH-539](https://github.com/apache/cordova-android/pull/539) Fix destination path fallback
|
|
||||||
* [GH-544](https://github.com/apache/cordova-android/pull/544) Remove obsolete check for JellyBean
|
|
||||||
* [GH-465](https://github.com/apache/cordova-android/pull/465) Removes Gradle property in-line command arguments for `gradle.properties`
|
|
||||||
* [GH-523](https://github.com/apache/cordova-android/pull/523) Always put the Google repo above jcenter
|
|
||||||
* [GH-486](https://github.com/apache/cordova-android/pull/486) Change deprecated "compile" to "implementation"
|
|
||||||
* [GH-495](https://github.com/apache/cordova-android/pull/495) Incorrect default sdk version issue fix
|
|
||||||
* [GH-493](https://github.com/apache/cordova-android/pull/493) Remove bundled dependencies
|
|
||||||
* [GH-490](https://github.com/apache/cordova-android/pull/490) Fixes build & run related bugs from builder refactor
|
|
||||||
* [GH-464](https://github.com/apache/cordova-android/pull/464) Unit tests for **Android**_sdk and **Android**Project
|
|
||||||
* [GH-448](https://github.com/apache/cordova-android/pull/448) [CB-13685](https://issues.apache.org/jira/browse/CB-13685) Adaptive Icon Support
|
|
||||||
* [GH-487](https://github.com/apache/cordova-android/pull/487) Do not attempt an activity intent AND a url load into the webview, return from the internal webview load.
|
|
||||||
* [GH-461](https://github.com/apache/cordova-android/pull/461) Remove old builders code
|
|
||||||
* [GH-463](https://github.com/apache/cordova-android/pull/463) Emulator: Add unit tests and remove Q
|
|
||||||
* [GH-462](https://github.com/apache/cordova-android/pull/462) Device: Add unit tests and remove Q
|
|
||||||
* [GH-457](https://github.com/apache/cordova-android/pull/457) Emulator: handle "device still connecting" error
|
|
||||||
* [GH-445](https://github.com/apache/cordova-android/pull/445) Run and retryPromise improvements and tests
|
|
||||||
* [GH-453](https://github.com/apache/cordova-android/pull/453) Lint JS files w/out extension too
|
|
||||||
* [GH-452](https://github.com/apache/cordova-android/pull/452) Emit log event instead of logging directly
|
|
||||||
* [GH-449](https://github.com/apache/cordova-android/pull/449) Increase old plugin compatibility
|
|
||||||
* [GH-442](https://github.com/apache/cordova-android/pull/442) Fixes and cleanup for Java tests and CI
|
|
||||||
* [GH-446](https://github.com/apache/cordova-android/pull/446) [CB-14101](https://issues.apache.org/jira/browse/CB-14101) Fix Java version check for Java >= 9
|
|
||||||
* [CB-14127](https://issues.apache.org/jira/browse/CB-14127) Move google maven repo ahead of jcenter
|
|
||||||
* [CB-14038](https://issues.apache.org/jira/browse/CB-14038) Fix false positive detecting project type
|
|
||||||
* [CB-14008](https://issues.apache.org/jira/browse/CB-14008) Updating Gradle Libraries to work with **Android** Studio 3.1.0
|
|
||||||
* [CB-13975](https://issues.apache.org/jira/browse/CB-13975) Fix to fire pause event when cdvStartInBackground=true
|
|
||||||
* [CB-13830](https://issues.apache.org/jira/browse/CB-13830) Add handlers for plugins that use non-Java source files, such as Camera
|
|
||||||
* [CB-13923](https://issues.apache.org/jira/browse/CB-13923) Fix -1 length for compressed files
|
|
||||||
|
|
||||||
### 7.1.4 (Nov 22, 2018)
|
|
||||||
|
|
||||||
* Update android-versions to `1.4.0`, with added support for Android Pie ([#573](https://github.com/apache/cordova-android/pull/573))
|
|
||||||
* Output current package name if package name can't be validated ([#567](https://github.com/apache/cordova-android/pull/567))
|
|
||||||
* Resolve issue with plugin `target-dir="*app*"` subdirs ([#572](https://github.com/apache/cordova-android/pull/572))
|
|
||||||
|
|
||||||
### 7.1.3 (Nov 19, 2018)
|
|
||||||
|
|
||||||
* [GH-495](https://github.com/apache/cordova-android/pull/495) Incorrect default sdk version issue fix
|
|
||||||
* [GH-496](https://github.com/apache/cordova-android/pull/496) update comments in `build.gradle`
|
|
||||||
* [GH-539](https://github.com/apache/cordova-android/pull/539) Fix dest overwrite, in case of of plugin `source-file` element with `target-dir` that does not need remapping
|
|
||||||
* [GH-540](https://github.com/apache/cordova-android/issues/540) support plugin `source-file` element with any app `target-dir` value
|
|
||||||
* [GH-547](https://github.com/apache/cordova-android/issues/547) Compatibility of old plugins with non-Java `source-file` entries (individual files)
|
|
||||||
* [GH-551](https://github.com/apache/cordova-android/pull/551) add missing cast for cdvMinSdkVersion to `build.gradle`
|
|
||||||
* [GH-552](https://github.com/apache/cordova-android/issues/552) check for `build-extras.gradle` in the parent app directory
|
|
||||||
|
|
||||||
### 7.1.2 (Nov 08, 2018)
|
|
||||||
* [CB-14127](https://issues.apache.org/jira/browse/CB-14127): Always put the Google repo above jcenter
|
|
||||||
* [CB-14165](https://issues.apache.org/jira/browse/CB-14165): Emulator: handle "device still connecting" error (#457)
|
|
||||||
* [CB-14125](https://issues.apache.org/jira/browse/CB-14125): Increase old plugin compatibility
|
|
||||||
* [CB-13830](https://issues.apache.org/jira/browse/CB-13830): Add handlers for plugins that use non-Java source files, such as Camera
|
|
||||||
* [CB-14038](https://issues.apache.org/jira/browse/CB-14038): fix false positive detecting project type
|
|
||||||
|
|
||||||
### 7.1.1 (Jul 11, 2018)
|
|
||||||
* Fix unsafe property access in run.js (#445)
|
|
||||||
* Emit log event instead of logging directly (#452)
|
|
||||||
* [CB-14101](https://issues.apache.org/jira/browse/CB-14101) Fix Java version check for Java >= 9 (#446)
|
|
||||||
* [CB-14127](https://issues.apache.org/jira/browse/CB-14127) (android) Move google maven repo ahead of jcenter
|
|
||||||
* [CB-13923](https://issues.apache.org/jira/browse/CB-13923) (android) fix -1 length for compressed files
|
|
||||||
* [CB-14145](https://issues.apache.org/jira/browse/CB-14145) use cordova-common@2.2.5 and update other dependencies to resolve `npm audit` warnings
|
|
||||||
* [CB-9366](https://issues.apache.org/jira/browse/CB-9366) log error.stack in cordova.js
|
|
||||||
|
|
||||||
### 7.1.0 (Feb 20, 2018)
|
|
||||||
* [CB-13879](https://issues.apache.org/jira/browse/CB-13879) updated gradle tools dependency to 3.0.1 for project template
|
|
||||||
* [CB-13831](https://issues.apache.org/jira/browse/CB-13831) Update `android-versions` to 1.3.0 to support SDK 27.
|
|
||||||
* [CB-13800](https://issues.apache.org/jira/browse/CB-13800) Drop pre-KitKat specific code
|
|
||||||
* [CB-13724](https://issues.apache.org/jira/browse/CB-13724) Updated the **Android** Tooling required for the latest version on both the test project, and the template
|
|
||||||
* [CB-13724](https://issues.apache.org/jira/browse/CB-13724) Bump Target SDK to API 27
|
|
||||||
* [CB-13646](https://issues.apache.org/jira/browse/CB-13646) Using the deprecated `NDK` by default breaks the build. Crosswalk users need to specify the Gradle parameters to keep it working.
|
|
||||||
* [CB-12218](https://issues.apache.org/jira/browse/CB-12218) Fix consistency of null result message
|
|
||||||
* [CB-13571](https://issues.apache.org/jira/browse/CB-13571) Prevent crash with unrecognized **Android** version
|
|
||||||
* [CB-13721](https://issues.apache.org/jira/browse/CB-13721) Fix build apps that use `cdvHelpers.getConfigPreference`
|
|
||||||
* [CB-13621](https://issues.apache.org/jira/browse/CB-13621) Wrote similar warning to [CB-12948](https://issues.apache.org/jira/browse/CB-12948) on **iOS**. We no longer support `cordova update` command.
|
|
||||||
|
|
||||||
### 7.0.0 (Nov 30, 2017)
|
### 7.0.0 (Nov 30, 2017)
|
||||||
* [CB-13612](https://issues.apache.org/jira/browse/CB-13612) Fix the remapper so that XML files copy over and the Camera works again.
|
* [CB-13612](https://issues.apache.org/jira/browse/CB-13612) Fix the remapper so that XML files copy over and the Camera works again.
|
||||||
|
38
appveyor.yml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
image:
|
||||||
|
- Previous Visual Studio 2015
|
||||||
|
|
||||||
|
environment:
|
||||||
|
ANDROID_HOME: "C:\\android"
|
||||||
|
matrix:
|
||||||
|
- nodejs_version: "4"
|
||||||
|
- nodejs_version: "6"
|
||||||
|
- nodejs_version: "8"
|
||||||
|
|
||||||
|
init:
|
||||||
|
- mkdir "%ANDROID_HOME%
|
||||||
|
- cd "%ANDROID_HOME%"
|
||||||
|
- appveyor DownloadFile "https://dl.google.com/android/repository/tools_r25.2.3-windows.zip"
|
||||||
|
- 7z x "tools_r25.2.3-windows.zip" > nul
|
||||||
|
- cd "C:\projects\cordova-android"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- choco install gradle -version 3.4.1
|
||||||
|
- gradle -version
|
||||||
|
- echo y | "%ANDROID_HOME%\tools\android.bat" --silent update sdk --no-ui --all --filter platform-tools,tools,build-tools-26.0.2,android-26,android-25,extra-google-m2repository,extra-android-m2repository
|
||||||
|
# on windows we need to accept sublicenses for the new tooling, wee. 30 is an arbitrary number,
|
||||||
|
# but should be the maximum number of licenses we explicitly need to type "Y ENTER" for.
|
||||||
|
# also, the sdkmanager in all its glory leaks a bit of output to stderr, and powershell
|
||||||
|
# and appveyor interpret that as errors, and blows up. so, when piping in our "Y ENTER"
|
||||||
|
# responses, we invoke cmd so we can redirect stderr to stdout, and tell it to --update itself.
|
||||||
|
- ps: for($i=0;$i -lt 30;$i++) { $response += "y`n"}; $response | cmd /c 'C:\android\tools\bin\sdkmanager.bat 2>&1' --update
|
||||||
|
- ps: Install-Product node $env:nodejs_version
|
||||||
|
- npm install
|
||||||
|
# below is a workaround on using gradle installed via choco on appveyor
|
||||||
|
- set path=C:\ProgramData\chocolatey\lib\gradle\tools\gradle-3.4.1\bin;%path%
|
||||||
|
|
||||||
|
build: off
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- node --version
|
||||||
|
- npm --version
|
||||||
|
- npm test
|
@ -19,9 +19,11 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const android_sdk = require('cordova-android/lib/android_sdk');
|
var android_sdk = require('./templates/cordova/lib/android_sdk');
|
||||||
|
|
||||||
android_sdk.print_newest_available_sdk_target().catch(err => {
|
android_sdk.print_newest_available_sdk_target().done(null, function(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
26
bin/android_sdk_version.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0android_sdk_version"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'android_sdk_version' script in 'bin' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
21
test/clean.js → bin/check_reqs
Normal file → Executable file
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
@ -17,16 +19,13 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
var check_reqs = require('./templates/cordova/lib/check_reqs');
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
/**
|
check_reqs.run().done(
|
||||||
* This script is to be run manually (e.g. by npm run clean:java-unit-tests) if
|
function success() {
|
||||||
* you want to upgrade gradlew or test its proper generation.
|
console.log('Looks like your environment fully supports cordova-android development!');
|
||||||
*/
|
}, function fail(err) {
|
||||||
|
console.log(err);
|
||||||
for (const variant of ['androidx']) {
|
process.exit(2);
|
||||||
for (const file of ['gradlew', 'gradlew.bat']) {
|
|
||||||
fs.removeSync(path.join(__dirname, variant, file));
|
|
||||||
}
|
}
|
||||||
}
|
);
|
26
bin/check_reqs.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0check_reqs"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'check_reqs' script in 'bin' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
58
bin/create
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
var path = require('path');
|
||||||
|
var ConfigParser = require('cordova-common').ConfigParser;
|
||||||
|
var Api = require('./templates/cordova/Api');
|
||||||
|
|
||||||
|
var argv = require('nopt')({
|
||||||
|
'help' : Boolean,
|
||||||
|
'cli' : Boolean,
|
||||||
|
'shared' : Boolean,
|
||||||
|
'link' : Boolean,
|
||||||
|
'activity-name' : [String, undefined]
|
||||||
|
}, { 'd' : '--verbose' });
|
||||||
|
|
||||||
|
if (argv.help || argv.argv.remain.length === 0) {
|
||||||
|
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' <path_to_new_project> <package_name> <project_name> [<template_path>] [--activity-name <activity_name>] [--link]');
|
||||||
|
console.log(' <path_to_new_project>: Path to your new Cordova Android project');
|
||||||
|
console.log(' <package_name>: Package name, following reverse-domain style convention');
|
||||||
|
console.log(' <project_name>: Project name');
|
||||||
|
console.log(' <template_path>: Path to a custom application template to use');
|
||||||
|
console.log(' --activity-name <activity_name>: Activity name');
|
||||||
|
console.log(' --link will use the CordovaLib project directly instead of making a copy.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = new ConfigParser(path.resolve(__dirname, 'templates/project/res/xml/config.xml'));
|
||||||
|
|
||||||
|
if (argv.argv.remain[1]) config.setPackageName(argv.argv.remain[1]);
|
||||||
|
if (argv.argv.remain[2]) config.setName(argv.argv.remain[2]);
|
||||||
|
if (argv['activity-name']) config.setName(argv['activity-name']);
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
link: argv.link || argv.shared,
|
||||||
|
customTemplate: argv.argv.remain[3],
|
||||||
|
activityName: argv['activity-name']
|
||||||
|
};
|
||||||
|
|
||||||
|
require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv);
|
||||||
|
|
||||||
|
Api.createPlatform(argv.argv.remain[0], config, options).done();
|
26
bin/create.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0create"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'create' script in 'bin' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
360
bin/lib/create.js
Executable file
@ -0,0 +1,360 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var Q = require('q');
|
||||||
|
var path = require('path');
|
||||||
|
var fs = require('fs');
|
||||||
|
var check_reqs = require('./../templates/cordova/lib/check_reqs');
|
||||||
|
var ROOT = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var AndroidManifest = require('../templates/cordova/lib/AndroidManifest');
|
||||||
|
|
||||||
|
// Export all helper functions, and make sure internally within this module, we
|
||||||
|
// reference these methods via the `exports` object - this helps with testing
|
||||||
|
// (since we can then mock and control behaviour of all of these functions)
|
||||||
|
exports.validatePackageName = validatePackageName;
|
||||||
|
exports.validateProjectName = validateProjectName;
|
||||||
|
exports.setShellFatal = setShellFatal;
|
||||||
|
exports.copyJsAndLibrary = copyJsAndLibrary;
|
||||||
|
exports.copyScripts = copyScripts;
|
||||||
|
exports.copyBuildRules = copyBuildRules;
|
||||||
|
exports.writeProjectProperties = writeProjectProperties;
|
||||||
|
exports.prepBuildFiles = prepBuildFiles;
|
||||||
|
|
||||||
|
function setShellFatal (value, func) {
|
||||||
|
var oldVal = shell.config.fatal;
|
||||||
|
shell.config.fatal = value;
|
||||||
|
func();
|
||||||
|
shell.config.fatal = oldVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFrameworkDir (projectPath, shared) {
|
||||||
|
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyJsAndLibrary (projectPath, shared, projectName, isLegacy) {
|
||||||
|
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
|
||||||
|
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
|
||||||
|
var app_path = path.join(projectPath, 'app', 'src', 'main');
|
||||||
|
|
||||||
|
if (isLegacy) {
|
||||||
|
app_path = projectPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.cp('-f', srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
||||||
|
|
||||||
|
// Copy the cordova.js file to platforms/<platform>/platform_www/
|
||||||
|
// The www dir is nuked on each prepare so we keep cordova.js in platform_www
|
||||||
|
shell.mkdir('-p', path.join(projectPath, 'platform_www'));
|
||||||
|
shell.cp('-f', srcCordovaJsPath, path.join(projectPath, 'platform_www'));
|
||||||
|
|
||||||
|
// Copy cordova-js-src directory into platform_www directory.
|
||||||
|
// We need these files to build cordova.js if using browserify method.
|
||||||
|
shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), path.join(projectPath, 'platform_www'));
|
||||||
|
|
||||||
|
// Don't fail if there are no old jars.
|
||||||
|
exports.setShellFatal(false, function () {
|
||||||
|
shell.ls(path.join(app_path, 'libs', 'cordova-*.jar')).forEach(function (oldJar) {
|
||||||
|
console.log('Deleting ' + oldJar);
|
||||||
|
shell.rm('-f', oldJar);
|
||||||
|
});
|
||||||
|
var wasSymlink = true;
|
||||||
|
try {
|
||||||
|
// Delete the symlink if it was one.
|
||||||
|
fs.unlinkSync(nestedCordovaLibPath);
|
||||||
|
} catch (e) {
|
||||||
|
wasSymlink = false;
|
||||||
|
}
|
||||||
|
// Delete old library project if it existed.
|
||||||
|
if (shared) {
|
||||||
|
shell.rm('-rf', nestedCordovaLibPath);
|
||||||
|
} else if (!wasSymlink) {
|
||||||
|
// Delete only the src, since Eclipse / Android Studio can't handle their project files being deleted.
|
||||||
|
shell.rm('-rf', path.join(nestedCordovaLibPath, 'src'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (shared) {
|
||||||
|
var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true));
|
||||||
|
fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
|
||||||
|
} else {
|
||||||
|
shell.mkdir('-p', nestedCordovaLibPath);
|
||||||
|
shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
|
||||||
|
shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
|
||||||
|
shell.cp('-f', path.join(ROOT, 'framework', 'build.gradle'), nestedCordovaLibPath);
|
||||||
|
shell.cp('-f', path.join(ROOT, 'framework', 'cordova.gradle'), nestedCordovaLibPath);
|
||||||
|
shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractSubProjectPaths (data) {
|
||||||
|
var ret = {};
|
||||||
|
var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg;
|
||||||
|
var m;
|
||||||
|
while ((m = r.exec(data))) {
|
||||||
|
ret[m[1]] = 1;
|
||||||
|
}
|
||||||
|
return Object.keys(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeProjectProperties (projectPath, target_api) {
|
||||||
|
var dstPath = path.join(projectPath, 'project.properties');
|
||||||
|
var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties');
|
||||||
|
var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath;
|
||||||
|
|
||||||
|
var data = fs.readFileSync(srcPath, 'utf8');
|
||||||
|
data = data.replace(/^target=.*/m, 'target=' + target_api);
|
||||||
|
var subProjects = extractSubProjectPaths(data);
|
||||||
|
subProjects = subProjects.filter(function (p) {
|
||||||
|
return !(/^CordovaLib$/m.exec(p) ||
|
||||||
|
/[\\/]cordova-android[\\/]framework$/m.exec(p) ||
|
||||||
|
/^(\.\.[\\/])+framework$/m.exec(p));
|
||||||
|
});
|
||||||
|
subProjects.unshift('CordovaLib');
|
||||||
|
data = data.replace(/^\s*android\.library\.reference\.\d+=.*\n/mg, '');
|
||||||
|
if (!/\n$/.exec(data)) {
|
||||||
|
data += '\n';
|
||||||
|
}
|
||||||
|
for (var i = 0; i < subProjects.length; ++i) {
|
||||||
|
data += 'android.library.reference.' + (i + 1) + '=' + subProjects[i] + '\n';
|
||||||
|
}
|
||||||
|
fs.writeFileSync(dstPath, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This makes no sense, what if you're building with a different build system?
|
||||||
|
function prepBuildFiles (projectPath, builder) {
|
||||||
|
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders'));
|
||||||
|
buildModule.getBuilder(builder).prepBuildFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyBuildRules (projectPath, isLegacy) {
|
||||||
|
var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
|
||||||
|
|
||||||
|
if (isLegacy) {
|
||||||
|
// The project's build.gradle is identical to the earlier build.gradle, so it should still work
|
||||||
|
shell.cp('-f', path.join(srcDir, 'legacy', 'build.gradle'), projectPath);
|
||||||
|
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
||||||
|
} else {
|
||||||
|
shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath);
|
||||||
|
shell.cp('-f', path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app'));
|
||||||
|
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyScripts (projectPath) {
|
||||||
|
var bin = path.join(ROOT, 'bin');
|
||||||
|
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
|
||||||
|
var destScriptsDir = path.join(projectPath, 'cordova');
|
||||||
|
// Delete old scripts directory if this is an update.
|
||||||
|
shell.rm('-rf', destScriptsDir);
|
||||||
|
// Copy in the new ones.
|
||||||
|
shell.cp('-r', srcScriptsDir, projectPath);
|
||||||
|
shell.cp('-r', path.join(ROOT, 'node_modules'), destScriptsDir);
|
||||||
|
shell.cp(path.join(bin, 'check_reqs*'), destScriptsDir);
|
||||||
|
shell.cp(path.join(bin, 'android_sdk_version*'), destScriptsDir);
|
||||||
|
var check_reqs = path.join(destScriptsDir, 'check_reqs');
|
||||||
|
var android_sdk_version = path.join(destScriptsDir, 'android_sdk_version');
|
||||||
|
// TODO: the two files being edited on-the-fly here are shared between
|
||||||
|
// platform and project-level commands. the below `sed` is updating the
|
||||||
|
// `require` path for the two libraries. if there's a better way to share
|
||||||
|
// modules across both the repo and generated projects, we should make sure
|
||||||
|
// to remove/update this.
|
||||||
|
shell.sed('-i', /templates\/cordova\//, '', android_sdk_version);
|
||||||
|
shell.sed('-i', /templates\/cordova\//, '', check_reqs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether a package name is acceptable for use as an android project.
|
||||||
|
* Returns a promise, fulfilled if the package name is acceptable; rejected
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
function validatePackageName (package_name) {
|
||||||
|
// Make the package conform to Java package types
|
||||||
|
// http://developer.android.com/guide/topics/manifest/manifest-element.html#package
|
||||||
|
// Enforce underscore limitation
|
||||||
|
var msg = 'Error validating package name. ';
|
||||||
|
|
||||||
|
if (!/^[a-zA-Z][a-zA-Z0-9_]+(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.test(package_name)) {
|
||||||
|
return Q.reject(new CordovaError(msg + 'Package name must look like: com.company.Name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Class is a reserved word
|
||||||
|
if (/\b[Cc]lass\b/.test(package_name)) {
|
||||||
|
return Q.reject(new CordovaError(msg + '"class" is a reserved word'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether a project name is acceptable for use as an android class.
|
||||||
|
* Returns a promise, fulfilled if the project name is acceptable; rejected
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
function validateProjectName (project_name) {
|
||||||
|
var msg = 'Error validating project name. ';
|
||||||
|
// Make sure there's something there
|
||||||
|
if (project_name === '') {
|
||||||
|
return Q.reject(new CordovaError(msg + 'Project name cannot be empty'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enforce stupid name error
|
||||||
|
if (project_name === 'CordovaActivity') {
|
||||||
|
return Q.reject(new CordovaError(msg + 'Project name cannot be CordovaActivity'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Classes in Java don't begin with numbers
|
||||||
|
if (/^[0-9]/.test(project_name)) {
|
||||||
|
return Q.reject(new CordovaError(msg + 'Project name must not begin with a number'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an android application with the given options.
|
||||||
|
*
|
||||||
|
* @param {String} project_path Path to the new Cordova android project.
|
||||||
|
* @param {ConfigParser} config Instance of ConfigParser to retrieve basic
|
||||||
|
* project properties.
|
||||||
|
* @param {Object} [options={}] Various options
|
||||||
|
* @param {String} [options.activityName='MainActivity'] Name for the
|
||||||
|
* activity
|
||||||
|
* @param {Boolean} [options.link=false] Specifies whether javascript files
|
||||||
|
* and CordovaLib framework will be symlinked to created application.
|
||||||
|
* @param {String} [options.customTemplate] Path to project template
|
||||||
|
* (override)
|
||||||
|
* @param {EventEmitter} [events] An EventEmitter instance for logging
|
||||||
|
* events
|
||||||
|
*
|
||||||
|
* @return {Promise<String>} Directory where application has been created
|
||||||
|
*/
|
||||||
|
exports.create = function (project_path, config, options, events) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
// Set default values for path, package and name
|
||||||
|
project_path = path.relative(process.cwd(), (project_path || 'CordovaExample'));
|
||||||
|
// Check if project already exists
|
||||||
|
if (fs.existsSync(project_path)) {
|
||||||
|
return Q.reject(new CordovaError('Project already exists! Delete and recreate'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
|
||||||
|
var project_name = config.name() ?
|
||||||
|
config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
|
||||||
|
|
||||||
|
var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity';
|
||||||
|
var target_api = check_reqs.get_target();
|
||||||
|
|
||||||
|
// Make the package conform to Java package types
|
||||||
|
return exports.validatePackageName(package_name)
|
||||||
|
.then(function () {
|
||||||
|
exports.validateProjectName(project_name);
|
||||||
|
}).then(function () {
|
||||||
|
// Log the given values for the project
|
||||||
|
events.emit('log', 'Creating Cordova project for the Android platform:');
|
||||||
|
events.emit('log', '\tPath: ' + project_path);
|
||||||
|
events.emit('log', '\tPackage: ' + package_name);
|
||||||
|
events.emit('log', '\tName: ' + project_name);
|
||||||
|
events.emit('log', '\tActivity: ' + safe_activity_name);
|
||||||
|
events.emit('log', '\tAndroid target: ' + target_api);
|
||||||
|
|
||||||
|
events.emit('verbose', 'Copying android template project to ' + project_path);
|
||||||
|
|
||||||
|
exports.setShellFatal(true, function () {
|
||||||
|
var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
|
||||||
|
var app_path = path.join(project_path, 'app', 'src', 'main');
|
||||||
|
|
||||||
|
// copy project template
|
||||||
|
shell.mkdir('-p', app_path);
|
||||||
|
shell.cp('-r', path.join(project_template_dir, 'assets'), app_path);
|
||||||
|
shell.cp('-r', path.join(project_template_dir, 'res'), app_path);
|
||||||
|
shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||||
|
|
||||||
|
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
||||||
|
shell.mkdir(path.join(app_path, 'libs'));
|
||||||
|
|
||||||
|
// copy cordova.js, cordova.jar
|
||||||
|
exports.copyJsAndLibrary(project_path, options.link, safe_activity_name);
|
||||||
|
|
||||||
|
// Set up ther Android Studio paths
|
||||||
|
var java_path = path.join(app_path, 'java');
|
||||||
|
var assets_path = path.join(app_path, 'assets');
|
||||||
|
var resource_path = path.join(app_path, 'res');
|
||||||
|
shell.mkdir('-p', java_path);
|
||||||
|
shell.mkdir('-p', assets_path);
|
||||||
|
shell.mkdir('-p', resource_path);
|
||||||
|
|
||||||
|
// interpolate the activity name and package
|
||||||
|
var packagePath = package_name.replace(/\./g, path.sep);
|
||||||
|
var activity_dir = path.join(java_path, packagePath);
|
||||||
|
var activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
||||||
|
|
||||||
|
shell.mkdir('-p', activity_dir);
|
||||||
|
shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
|
||||||
|
shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
|
||||||
|
shell.sed('-i', /__NAME__/, project_name, path.join(app_path, 'res', 'values', 'strings.xml'));
|
||||||
|
shell.sed('-i', /__ID__/, package_name, activity_path);
|
||||||
|
|
||||||
|
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
||||||
|
manifest.setPackageId(package_name)
|
||||||
|
.setTargetSdkVersion(target_api.split('-')[1])
|
||||||
|
.getActivity().setName(safe_activity_name);
|
||||||
|
|
||||||
|
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
||||||
|
manifest.write(manifest_path);
|
||||||
|
|
||||||
|
exports.copyScripts(project_path);
|
||||||
|
exports.copyBuildRules(project_path);
|
||||||
|
});
|
||||||
|
// Link it to local android install.
|
||||||
|
exports.writeProjectProperties(project_path, target_api);
|
||||||
|
exports.prepBuildFiles(project_path, 'studio');
|
||||||
|
events.emit('log', generateDoneMessage('create', options.link));
|
||||||
|
}).thenResolve(project_path);
|
||||||
|
};
|
||||||
|
|
||||||
|
function generateDoneMessage (type, link) {
|
||||||
|
var pkg = require('../../package');
|
||||||
|
var msg = 'Android project ' + (type === 'update' ? 'updated ' : 'created ') + 'with ' + pkg.name + '@' + pkg.version;
|
||||||
|
if (link) {
|
||||||
|
msg += ' and has a linked CordovaLib';
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
exports.update = function (projectPath, options, events) {
|
||||||
|
|
||||||
|
var errorString =
|
||||||
|
'An in-place platform update is not supported. \n' +
|
||||||
|
'The `platforms` folder is always treated as a build artifact in the CLI workflow.\n' +
|
||||||
|
'To update your platform, you have to remove, then add your android platform again.\n' +
|
||||||
|
'Make sure you save your plugins beforehand using `cordova plugin save`, and save \n' + 'a copy of the platform first if you had manual changes in it.\n' +
|
||||||
|
'\tcordova plugin save\n' +
|
||||||
|
'\tcordova platform rm android\n' +
|
||||||
|
'\tcordova platform add android\n'
|
||||||
|
;
|
||||||
|
|
||||||
|
return Q.reject(errorString);
|
||||||
|
};
|
411
bin/templates/cordova/Api.js
vendored
Normal file
@ -0,0 +1,411 @@
|
|||||||
|
/**
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
|
var Q = require('q');
|
||||||
|
|
||||||
|
var AndroidProject = require('./lib/AndroidProject');
|
||||||
|
var AndroidStudio = require('./lib/AndroidStudio');
|
||||||
|
var PluginManager = require('cordova-common').PluginManager;
|
||||||
|
|
||||||
|
var CordovaLogger = require('cordova-common').CordovaLogger;
|
||||||
|
var selfEvents = require('cordova-common').events;
|
||||||
|
|
||||||
|
var PLATFORM = 'android';
|
||||||
|
|
||||||
|
function setupEvents (externalEventEmitter) {
|
||||||
|
if (externalEventEmitter) {
|
||||||
|
// This will make the platform internal events visible outside
|
||||||
|
selfEvents.forwardEventsTo(externalEventEmitter);
|
||||||
|
return externalEventEmitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is no logger if external emitter is not present,
|
||||||
|
// so attach a console logger
|
||||||
|
CordovaLogger.get().subscribe(selfEvents);
|
||||||
|
return selfEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class, that acts as abstraction over particular platform. Encapsulates the
|
||||||
|
* platform's properties and methods.
|
||||||
|
*
|
||||||
|
* Platform that implements own PlatformApi instance _should implement all
|
||||||
|
* prototype methods_ of this class to be fully compatible with cordova-lib.
|
||||||
|
*
|
||||||
|
* The PlatformApi instance also should define the following field:
|
||||||
|
*
|
||||||
|
* * platform: String that defines a platform name.
|
||||||
|
*/
|
||||||
|
function Api (platform, platformRootDir, events) {
|
||||||
|
this.platform = PLATFORM;
|
||||||
|
this.root = path.resolve(__dirname, '..');
|
||||||
|
this.builder = 'gradle';
|
||||||
|
|
||||||
|
setupEvents(events);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.locations = {
|
||||||
|
root: self.root,
|
||||||
|
www: path.join(self.root, 'assets/www'),
|
||||||
|
res: path.join(self.root, 'res'),
|
||||||
|
platformWww: path.join(self.root, 'platform_www'),
|
||||||
|
configXml: path.join(self.root, 'res/xml/config.xml'),
|
||||||
|
defaultConfigXml: path.join(self.root, 'cordova/defaults.xml'),
|
||||||
|
strings: path.join(self.root, 'res/values/strings.xml'),
|
||||||
|
manifest: path.join(self.root, 'AndroidManifest.xml'),
|
||||||
|
build: path.join(self.root, 'build'),
|
||||||
|
javaSrc: path.join(self.root, 'src'),
|
||||||
|
// NOTE: Due to platformApi spec we need to return relative paths here
|
||||||
|
cordovaJs: 'bin/templates/project/assets/www/cordova.js',
|
||||||
|
cordovaJsSrc: 'cordova-js-src'
|
||||||
|
};
|
||||||
|
|
||||||
|
// XXX Override some locations for Android Studio projects
|
||||||
|
if (AndroidStudio.isAndroidStudioProject(self.root) === true) {
|
||||||
|
selfEvents.emit('log', 'Android Studio project detected');
|
||||||
|
this.builder = 'studio';
|
||||||
|
this.android_studio = true;
|
||||||
|
this.locations.configXml = path.join(self.root, 'app/src/main/res/xml/config.xml');
|
||||||
|
this.locations.strings = path.join(self.root, 'app/src/main/res/values/strings.xml');
|
||||||
|
this.locations.manifest = path.join(self.root, 'app/src/main/AndroidManifest.xml');
|
||||||
|
// We could have Java Source, we could have other languages
|
||||||
|
this.locations.javaSrc = path.join(self.root, 'app/src/main/java/');
|
||||||
|
this.locations.www = path.join(self.root, 'app/src/main/assets/www');
|
||||||
|
this.locations.res = path.join(self.root, 'app/src/main/res');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs platform to specified directory and creates a platform project.
|
||||||
|
*
|
||||||
|
* @param {String} destination Destination directory, where insatll platform to
|
||||||
|
* @param {ConfigParser} [config] ConfgiParser instance, used to retrieve
|
||||||
|
* project creation options, such as package id and project name.
|
||||||
|
* @param {Object} [options] An options object. The most common options are:
|
||||||
|
* @param {String} [options.customTemplate] A path to custom template, that
|
||||||
|
* should override the default one from platform.
|
||||||
|
* @param {Boolean} [options.link] Flag that indicates that platform's
|
||||||
|
* sources will be linked to installed platform instead of copying.
|
||||||
|
* @param {EventEmitter} [events] An EventEmitter instance that will be used for
|
||||||
|
* logging purposes. If no EventEmitter provided, all events will be logged to
|
||||||
|
* console
|
||||||
|
*
|
||||||
|
* @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi
|
||||||
|
* instance or rejected with CordovaError.
|
||||||
|
*/
|
||||||
|
Api.createPlatform = function (destination, config, options, events) {
|
||||||
|
events = setupEvents(events);
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
|
||||||
|
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
|
||||||
|
return new PlatformApi(PLATFORM, destination, events);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
events.emit('error', 'createPlatform is not callable from the android project API.');
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates already installed platform.
|
||||||
|
*
|
||||||
|
* @param {String} destination Destination directory, where platform installed
|
||||||
|
* @param {Object} [options] An options object. The most common options are:
|
||||||
|
* @param {String} [options.customTemplate] A path to custom template, that
|
||||||
|
* should override the default one from platform.
|
||||||
|
* @param {Boolean} [options.link] Flag that indicates that platform's
|
||||||
|
* sources will be linked to installed platform instead of copying.
|
||||||
|
* @param {EventEmitter} [events] An EventEmitter instance that will be used for
|
||||||
|
* logging purposes. If no EventEmitter provided, all events will be logged to
|
||||||
|
* console
|
||||||
|
*
|
||||||
|
* @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi
|
||||||
|
* instance or rejected with CordovaError.
|
||||||
|
*/
|
||||||
|
Api.updatePlatform = function (destination, options, events) {
|
||||||
|
events = setupEvents(events);
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = require('../../lib/create').update(destination, options, events).then(function (destination) {
|
||||||
|
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
|
||||||
|
return new PlatformApi('android', destination, events);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
events.emit('error', 'updatePlatform is not callable from the android project API, you will need to do this manually.');
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a CordovaPlatform object, that represents the platform structure.
|
||||||
|
*
|
||||||
|
* @return {CordovaPlatform} A structure that contains the description of
|
||||||
|
* platform's file structure and other properties of platform.
|
||||||
|
*/
|
||||||
|
Api.prototype.getPlatformInfo = function () {
|
||||||
|
var result = {};
|
||||||
|
result.locations = this.locations;
|
||||||
|
result.root = this.root;
|
||||||
|
result.name = this.platform;
|
||||||
|
result.version = require('./version');
|
||||||
|
result.projectConfig = this._config;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates installed platform with provided www assets and new app
|
||||||
|
* configuration. This method is required for CLI workflow and will be called
|
||||||
|
* each time before build, so the changes, made to app configuration and www
|
||||||
|
* code, will be applied to platform.
|
||||||
|
*
|
||||||
|
* @param {CordovaProject} cordovaProject A CordovaProject instance, that defines a
|
||||||
|
* project structure and configuration, that should be applied to platform
|
||||||
|
* (contains project's www location and ConfigParser instance for project's
|
||||||
|
* config).
|
||||||
|
*
|
||||||
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
|
* CordovaError instance.
|
||||||
|
*/
|
||||||
|
Api.prototype.prepare = function (cordovaProject, prepareOptions) {
|
||||||
|
return require('./lib/prepare').prepare.call(this, cordovaProject, prepareOptions);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs a new plugin into platform. This method only copies non-www files
|
||||||
|
* (sources, libs, etc.) to platform. It also doesn't resolves the
|
||||||
|
* dependencies of plugin. Both of handling of www files, such as assets and
|
||||||
|
* js-files and resolving dependencies are the responsibility of caller.
|
||||||
|
*
|
||||||
|
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
|
||||||
|
* that will be installed.
|
||||||
|
* @param {Object} installOptions An options object. Possible options below:
|
||||||
|
* @param {Boolean} installOptions.link: Flag that specifies that plugin
|
||||||
|
* sources will be symlinked to app's directory instead of copying (if
|
||||||
|
* possible).
|
||||||
|
* @param {Object} installOptions.variables An object that represents
|
||||||
|
* variables that will be used to install plugin. See more details on plugin
|
||||||
|
* variables in documentation:
|
||||||
|
* https://cordova.apache.org/docs/en/4.0.0/plugin_ref_spec.md.html
|
||||||
|
*
|
||||||
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
|
* CordovaError instance.
|
||||||
|
*/
|
||||||
|
Api.prototype.addPlugin = function (plugin, installOptions) {
|
||||||
|
var project = AndroidProject.getProjectFile(this.root);
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
installOptions = installOptions || {};
|
||||||
|
installOptions.variables = installOptions.variables || {};
|
||||||
|
// Add PACKAGE_NAME variable into vars
|
||||||
|
if (!installOptions.variables.PACKAGE_NAME) {
|
||||||
|
installOptions.variables.PACKAGE_NAME = project.getPackageName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.android_studio === true) {
|
||||||
|
installOptions.android_studio = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q().then(function () {
|
||||||
|
// CB-11964: Do a clean when installing the plugin code to get around
|
||||||
|
// the Gradle bug introduced by the Android Gradle Plugin Version 2.2
|
||||||
|
// TODO: Delete when the next version of Android Gradle plugin comes out
|
||||||
|
// Since clean doesn't just clean the build, it also wipes out www, we need
|
||||||
|
// to pass additional options.
|
||||||
|
|
||||||
|
// Do some basic argument parsing
|
||||||
|
var opts = {};
|
||||||
|
|
||||||
|
// Skip cleaning prepared files when not invoking via cordova CLI.
|
||||||
|
opts.noPrepare = true;
|
||||||
|
|
||||||
|
if (!AndroidStudio.isAndroidStudioProject(self.root) && !project.isClean()) {
|
||||||
|
return self.clean(opts);
|
||||||
|
}
|
||||||
|
}).then(function () {
|
||||||
|
return PluginManager.get(self.platform, self.locations, project).addPlugin(plugin, installOptions);
|
||||||
|
}).then(function () {
|
||||||
|
if (plugin.getFrameworks(this.platform).length === 0) return;
|
||||||
|
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
||||||
|
// This should pick the correct builder, not just get gradle
|
||||||
|
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
||||||
|
}.bind(this))
|
||||||
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
|
.thenResolve(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an installed plugin from platform.
|
||||||
|
*
|
||||||
|
* Since method accepts PluginInfo instance as input parameter instead of plugin
|
||||||
|
* id, caller shoud take care of managing/storing PluginInfo instances for
|
||||||
|
* future uninstalls.
|
||||||
|
*
|
||||||
|
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
|
||||||
|
* that will be installed.
|
||||||
|
*
|
||||||
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
|
* CordovaError instance.
|
||||||
|
*/
|
||||||
|
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
|
||||||
|
var project = AndroidProject.getProjectFile(this.root);
|
||||||
|
|
||||||
|
if (uninstallOptions && uninstallOptions.usePlatformWww === true && this.android_studio === true) {
|
||||||
|
uninstallOptions.usePlatformWww = false;
|
||||||
|
uninstallOptions.android_studio = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PluginManager.get(this.platform, this.locations, project)
|
||||||
|
.removePlugin(plugin, uninstallOptions)
|
||||||
|
.then(function () {
|
||||||
|
if (plugin.getFrameworks(this.platform).length === 0) return;
|
||||||
|
|
||||||
|
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
||||||
|
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
||||||
|
}.bind(this))
|
||||||
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
|
.thenResolve(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an application package for current platform.
|
||||||
|
*
|
||||||
|
* @param {Object} buildOptions A build options. This object's structure is
|
||||||
|
* highly depends on platform's specific. The most common options are:
|
||||||
|
* @param {Boolean} buildOptions.debug Indicates that packages should be
|
||||||
|
* built with debug configuration. This is set to true by default unless the
|
||||||
|
* 'release' option is not specified.
|
||||||
|
* @param {Boolean} buildOptions.release Indicates that packages should be
|
||||||
|
* built with release configuration. If not set to true, debug configuration
|
||||||
|
* will be used.
|
||||||
|
* @param {Boolean} buildOptions.device Specifies that built app is intended
|
||||||
|
* to run on device
|
||||||
|
* @param {Boolean} buildOptions.emulator: Specifies that built app is
|
||||||
|
* intended to run on emulator
|
||||||
|
* @param {String} buildOptions.target Specifies the device id that will be
|
||||||
|
* used to run built application.
|
||||||
|
* @param {Boolean} buildOptions.nobuild Indicates that this should be a
|
||||||
|
* dry-run call, so no build artifacts will be produced.
|
||||||
|
* @param {String[]} buildOptions.archs Specifies chip architectures which
|
||||||
|
* app packages should be built for. List of valid architectures is depends on
|
||||||
|
* platform.
|
||||||
|
* @param {String} buildOptions.buildConfig The path to build configuration
|
||||||
|
* file. The format of this file is depends on platform.
|
||||||
|
* @param {String[]} buildOptions.argv Raw array of command-line arguments,
|
||||||
|
* passed to `build` command. The purpose of this property is to pass a
|
||||||
|
* platform-specific arguments, and eventually let platform define own
|
||||||
|
* arguments processing logic.
|
||||||
|
*
|
||||||
|
* @return {Promise<Object[]>} A promise either fulfilled with an array of build
|
||||||
|
* artifacts (application packages) if package was built successfully,
|
||||||
|
* or rejected with CordovaError. The resultant build artifact objects is not
|
||||||
|
* strictly typed and may conatin arbitrary set of fields as in sample below.
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* architecture: 'x86',
|
||||||
|
* buildType: 'debug',
|
||||||
|
* path: '/path/to/build',
|
||||||
|
* type: 'app'
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* The return value in most cases will contain only one item but in some cases
|
||||||
|
* there could be multiple items in output array, e.g. when multiple
|
||||||
|
* arhcitectures is specified.
|
||||||
|
*/
|
||||||
|
Api.prototype.build = function (buildOptions) {
|
||||||
|
var self = this;
|
||||||
|
if (this.android_studio) {
|
||||||
|
buildOptions.studio = true;
|
||||||
|
}
|
||||||
|
return require('./lib/check_reqs').run().then(function () {
|
||||||
|
return require('./lib/build').run.call(self, buildOptions);
|
||||||
|
}).then(function (buildResults) {
|
||||||
|
// Cast build result to array of build artifacts
|
||||||
|
return buildResults.apkPaths.map(function (apkPath) {
|
||||||
|
return {
|
||||||
|
buildType: buildResults.buildType,
|
||||||
|
buildMethod: buildResults.buildMethod,
|
||||||
|
path: apkPath,
|
||||||
|
type: 'apk'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an application package for current platform and runs it on
|
||||||
|
* specified/default device. If no 'device'/'emulator'/'target' options are
|
||||||
|
* specified, then tries to run app on default device if connected, otherwise
|
||||||
|
* runs the app on emulator.
|
||||||
|
*
|
||||||
|
* @param {Object} runOptions An options object. The structure is the same
|
||||||
|
* as for build options.
|
||||||
|
*
|
||||||
|
* @return {Promise} A promise either fulfilled if package was built and ran
|
||||||
|
* successfully, or rejected with CordovaError.
|
||||||
|
*/
|
||||||
|
Api.prototype.run = function (runOptions) {
|
||||||
|
var self = this;
|
||||||
|
return require('./lib/check_reqs').run().then(function () {
|
||||||
|
return require('./lib/run').run.call(self, runOptions);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans out the build artifacts from platform's directory, and also
|
||||||
|
* cleans out the platform www directory if called without options specified.
|
||||||
|
*
|
||||||
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
|
* CordovaError.
|
||||||
|
*/
|
||||||
|
Api.prototype.clean = function (cleanOptions) {
|
||||||
|
var self = this;
|
||||||
|
if (this.android_studio) {
|
||||||
|
// This will lint, checking for null won't
|
||||||
|
if (typeof cleanOptions === 'undefined') {
|
||||||
|
cleanOptions = {};
|
||||||
|
}
|
||||||
|
cleanOptions.studio = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return require('./lib/check_reqs').run().then(function () {
|
||||||
|
return require('./lib/build').runClean.call(self, cleanOptions);
|
||||||
|
}).then(function () {
|
||||||
|
return require('./lib/prepare').clean.call(self, cleanOptions);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a requirements check for current platform. Each platform defines its
|
||||||
|
* own set of requirements, which should be resolved before platform can be
|
||||||
|
* built successfully.
|
||||||
|
*
|
||||||
|
* @return {Promise<Requirement[]>} Promise, resolved with set of Requirement
|
||||||
|
* objects for current platform.
|
||||||
|
*/
|
||||||
|
Api.prototype.requirements = function () {
|
||||||
|
return require('./lib/check_reqs').check_all();
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Api;
|
50
bin/templates/cordova/build
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var args = process.argv;
|
||||||
|
var Api = require('./Api');
|
||||||
|
var nopt = require('nopt');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
// Support basic help commands
|
||||||
|
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0)
|
||||||
|
require('./lib/build').help();
|
||||||
|
|
||||||
|
// Do some basic argument parsing
|
||||||
|
var buildOpts = nopt({
|
||||||
|
'verbose' : Boolean,
|
||||||
|
'silent' : Boolean,
|
||||||
|
'debug' : Boolean,
|
||||||
|
'release' : Boolean,
|
||||||
|
'nobuild': Boolean,
|
||||||
|
'buildConfig' : path
|
||||||
|
}, { 'd' : '--verbose' });
|
||||||
|
|
||||||
|
// Make buildOptions compatible with PlatformApi build method spec
|
||||||
|
buildOpts.argv = buildOpts.argv.original;
|
||||||
|
|
||||||
|
require('./loggingHelper').adjustLoggerLevel(buildOpts);
|
||||||
|
|
||||||
|
new Api().build(buildOpts)
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error(err.stack);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
26
bin/templates/cordova/build.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0build"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'build' script in 'cordova' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
51
bin/templates/cordova/clean
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Api = require('./Api');
|
||||||
|
var path = require('path');
|
||||||
|
var nopt = require('nopt');
|
||||||
|
|
||||||
|
// Support basic help commands
|
||||||
|
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
|
||||||
|
console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]));
|
||||||
|
console.log('Cleans the project directory.');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do some basic argument parsing
|
||||||
|
var opts = nopt({
|
||||||
|
'verbose' : Boolean,
|
||||||
|
'silent' : Boolean
|
||||||
|
}, { 'd' : '--verbose' });
|
||||||
|
|
||||||
|
// Make buildOptions compatible with PlatformApi clean method spec
|
||||||
|
opts.argv = opts.argv.original;
|
||||||
|
|
||||||
|
// Skip cleaning prepared files when not invoking via cordova CLI.
|
||||||
|
opts.noPrepare = true;
|
||||||
|
|
||||||
|
require('./loggingHelper').adjustLoggerLevel(opts);
|
||||||
|
|
||||||
|
new Api().clean(opts)
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error(err.stack);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
26
bin/templates/cordova/clean.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0clean"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'clean' script in 'cordova' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
82
lib/Adb.js → bin/templates/cordova/lib/Adb.js
vendored
@ -17,47 +17,50 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const os = require('os');
|
var Q = require('q');
|
||||||
const execa = require('execa');
|
var os = require('os');
|
||||||
const events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
const CordovaError = require('cordova-common').CordovaError;
|
var spawn = require('cordova-common').superspawn.spawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
const Adb = {};
|
var Adb = {};
|
||||||
|
|
||||||
|
function isDevice (line) {
|
||||||
|
return line.match(/\w+\tdevice/) && !line.match(/emulator/);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEmulator (line) {
|
||||||
|
return line.match(/device/) && line.match(/emulator/);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists available/connected devices and emulators
|
* Lists available/connected devices and emulators
|
||||||
*
|
*
|
||||||
|
* @param {Object} opts Various options
|
||||||
|
* @param {Boolean} opts.emulators Specifies whether this method returns
|
||||||
|
* emulators only
|
||||||
|
*
|
||||||
* @return {Promise<String[]>} list of available/connected
|
* @return {Promise<String[]>} list of available/connected
|
||||||
* devices/emulators
|
* devices/emulators
|
||||||
*/
|
*/
|
||||||
Adb.devices = async function () {
|
Adb.devices = function (opts) {
|
||||||
const { stdout } = await execa('adb', ['devices'], { cwd: os.tmpdir() });
|
return spawn('adb', ['devices'], {cwd: os.tmpdir()}).then(function (output) {
|
||||||
|
return output.split('\n').filter(function (line) {
|
||||||
// Split into lines & drop first one (header)
|
// Filter out either real devices or emulators, depending on options
|
||||||
const rawDeviceLines = stdout.trim().split(/\r?\n/).slice(1);
|
return (line && opts && opts.emulators) ? isEmulator(line) : isDevice(line);
|
||||||
|
}).map(function (line) {
|
||||||
return rawDeviceLines
|
return line.replace(/\tdevice/, '').replace('\r', '');
|
||||||
.map(line => line.split('\t'))
|
});
|
||||||
|
});
|
||||||
// We are only interested in fully booted devices & emulators. These
|
|
||||||
// have a state of `device`. For a list of all the other possible states
|
|
||||||
// see https://github.com/aosp-mirror/platform_system_core/blob/2abdb1eb5b83c8f39874644af576c869815f5c5b/adb/transport.cpp#L1129
|
|
||||||
.filter(([, state]) => state === 'device')
|
|
||||||
|
|
||||||
.map(([id]) => id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Adb.install = function (target, packagePath, { replace = false, execOptions = {} } = {}) {
|
Adb.install = function (target, packagePath, opts) {
|
||||||
events.emit('verbose', 'Installing apk ' + packagePath + ' on target ' + target + '...');
|
events.emit('verbose', 'Installing apk ' + packagePath + ' on target ' + target + '...');
|
||||||
|
var args = ['-s', target, 'install'];
|
||||||
const args = ['-s', target, 'install'];
|
if (opts && opts.replace) args.push('-r');
|
||||||
if (replace) args.push('-r');
|
return spawn('adb', args.concat(packagePath), {cwd: os.tmpdir()}).then(function (output) {
|
||||||
|
// 'adb install' seems to always returns no error, even if installation fails
|
||||||
const opts = { cwd: os.tmpdir(), ...execOptions };
|
// so we catching output to detect installation failure
|
||||||
|
|
||||||
return execa('adb', args.concat(packagePath), opts).then(({ stdout: output }) => {
|
|
||||||
// adb does not return an error code even if installation fails. Instead it puts a specific
|
|
||||||
// message to stdout, so we have to use RegExp matching to detect installation failure.
|
|
||||||
if (output.match(/Failure/)) {
|
if (output.match(/Failure/)) {
|
||||||
if (output.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
|
if (output.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
|
||||||
output += '\n\n' + 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
|
output += '\n\n' + 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
|
||||||
@ -67,30 +70,31 @@ Adb.install = function (target, packagePath, { replace = false, execOptions = {}
|
|||||||
'\nEither uninstall an app or increment the versionCode.';
|
'\nEither uninstall an app or increment the versionCode.';
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CordovaError('Failed to install apk to target: ' + output);
|
return Q.reject(new CordovaError('Failed to install apk to device: ' + output));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Adb.uninstall = function (target, packageId) {
|
Adb.uninstall = function (target, packageId) {
|
||||||
events.emit('verbose', 'Uninstalling package ' + packageId + ' from target ' + target + '...');
|
events.emit('verbose', 'Uninstalling package ' + packageId + ' from target ' + target + '...');
|
||||||
return execa('adb', ['-s', target, 'uninstall', packageId], { cwd: os.tmpdir() }).then(({ stdout }) => stdout);
|
return spawn('adb', ['-s', target, 'uninstall', packageId], {cwd: os.tmpdir()});
|
||||||
};
|
};
|
||||||
|
|
||||||
Adb.shell = function (target, shellCommand) {
|
Adb.shell = function (target, shellCommand) {
|
||||||
events.emit('verbose', 'Running adb shell command "' + shellCommand + '" on target ' + target + '...');
|
events.emit('verbose', 'Running adb shell command "' + shellCommand + '" on target ' + target + '...');
|
||||||
const args = ['-s', target, 'shell'];
|
var args = ['-s', target, 'shell'];
|
||||||
shellCommand = shellCommand.split(/\s+/);
|
shellCommand = shellCommand.split(/\s+/);
|
||||||
return execa('adb', args.concat(shellCommand), { cwd: os.tmpdir() })
|
return spawn('adb', args.concat(shellCommand), {cwd: os.tmpdir()}).catch(function (output) {
|
||||||
.then(({ stdout }) => stdout)
|
return Q.reject(new CordovaError('Failed to execute shell command "' +
|
||||||
.catch(error => Promise.reject(new CordovaError(`Failed to execute shell command "${shellCommand}" on device: ${error}`)));
|
shellCommand + '"" on device: ' + output));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Adb.start = function (target, activityName) {
|
Adb.start = function (target, activityName) {
|
||||||
events.emit('verbose', 'Starting application "' + activityName + '" on target ' + target + '...');
|
events.emit('verbose', 'Starting application "' + activityName + '" on target ' + target + '...');
|
||||||
return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName).catch((error) => {
|
return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName).catch(function (output) {
|
||||||
return Promise.reject(new CordovaError('Failed to start application "' +
|
return Q.reject(new CordovaError('Failed to start application "' +
|
||||||
activityName + '"" on device: ' + error));
|
activityName + '"" on device: ' + output));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
160
bin/templates/cordova/lib/AndroidManifest.js
vendored
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/**
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var et = require('elementtree');
|
||||||
|
var xml = require('cordova-common').xmlHelpers;
|
||||||
|
|
||||||
|
var DEFAULT_ORIENTATION = 'default';
|
||||||
|
|
||||||
|
/** Wraps an AndroidManifest file */
|
||||||
|
function AndroidManifest (path) {
|
||||||
|
this.path = path;
|
||||||
|
this.doc = xml.parseElementtreeSync(path);
|
||||||
|
if (this.doc.getroot().tag !== 'manifest') {
|
||||||
|
throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidManifest.prototype.getVersionName = function () {
|
||||||
|
return this.doc.getroot().attrib['android:versionName'];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.setVersionName = function (versionName) {
|
||||||
|
this.doc.getroot().attrib['android:versionName'] = versionName;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.getVersionCode = function () {
|
||||||
|
return this.doc.getroot().attrib['android:versionCode'];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.setVersionCode = function (versionCode) {
|
||||||
|
this.doc.getroot().attrib['android:versionCode'] = versionCode;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.getPackageId = function () {
|
||||||
|
/* jshint -W069 */
|
||||||
|
return this.doc.getroot().attrib['package'];
|
||||||
|
/* jshint +W069 */
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.setPackageId = function (pkgId) {
|
||||||
|
/* jshint -W069 */
|
||||||
|
this.doc.getroot().attrib['package'] = pkgId;
|
||||||
|
/* jshint +W069 */
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.getActivity = function () {
|
||||||
|
var activity = this.doc.getroot().find('./application/activity');
|
||||||
|
return {
|
||||||
|
getName: function () {
|
||||||
|
return activity.attrib['android:name'];
|
||||||
|
},
|
||||||
|
setName: function (name) {
|
||||||
|
if (!name) {
|
||||||
|
delete activity.attrib['android:name'];
|
||||||
|
} else {
|
||||||
|
activity.attrib['android:name'] = name;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
getOrientation: function () {
|
||||||
|
return activity.attrib['android:screenOrientation'];
|
||||||
|
},
|
||||||
|
setOrientation: function (orientation) {
|
||||||
|
if (!orientation || orientation.toLowerCase() === DEFAULT_ORIENTATION) {
|
||||||
|
delete activity.attrib['android:screenOrientation'];
|
||||||
|
} else {
|
||||||
|
activity.attrib['android:screenOrientation'] = orientation;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
getLaunchMode: function () {
|
||||||
|
return activity.attrib['android:launchMode'];
|
||||||
|
},
|
||||||
|
setLaunchMode: function (launchMode) {
|
||||||
|
if (!launchMode) {
|
||||||
|
delete activity.attrib['android:launchMode'];
|
||||||
|
} else {
|
||||||
|
activity.attrib['android:launchMode'] = launchMode;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
['minSdkVersion', 'maxSdkVersion', 'targetSdkVersion'].forEach(function (sdkPrefName) {
|
||||||
|
// Copy variable reference to avoid closure issues
|
||||||
|
var prefName = sdkPrefName;
|
||||||
|
|
||||||
|
AndroidManifest.prototype['get' + capitalize(prefName)] = function () {
|
||||||
|
var usesSdk = this.doc.getroot().find('./uses-sdk');
|
||||||
|
return usesSdk && usesSdk.attrib['android:' + prefName];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype['set' + capitalize(prefName)] = function (prefValue) {
|
||||||
|
var usesSdk = this.doc.getroot().find('./uses-sdk');
|
||||||
|
|
||||||
|
if (!usesSdk && prefValue) { // if there is no required uses-sdk element, we should create it first
|
||||||
|
usesSdk = new et.Element('uses-sdk');
|
||||||
|
this.doc.getroot().append(usesSdk);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefValue) {
|
||||||
|
usesSdk.attrib['android:' + prefName] = prefValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
AndroidManifest.prototype.getDebuggable = function () {
|
||||||
|
return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype.setDebuggable = function (value) {
|
||||||
|
var application = this.doc.getroot().find('./application');
|
||||||
|
if (value) {
|
||||||
|
application.attrib['android:debuggable'] = 'true';
|
||||||
|
} else {
|
||||||
|
// The default value is "false", so we can remove attribute at all.
|
||||||
|
delete application.attrib['android:debuggable'];
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes manifest to disk syncronously. If filename is specified, then manifest
|
||||||
|
* will be written to that file
|
||||||
|
*
|
||||||
|
* @param {String} [destPath] File to write manifest to. If omitted,
|
||||||
|
* manifest will be written to file it has been read from.
|
||||||
|
*/
|
||||||
|
AndroidManifest.prototype.write = function (destPath) {
|
||||||
|
fs.writeFileSync(destPath || this.path, this.doc.write({indent: 4}), 'utf-8');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = AndroidManifest;
|
||||||
|
|
||||||
|
function capitalize (str) {
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
|
}
|
209
bin/templates/cordova/lib/AndroidProject.js
vendored
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
/**
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var properties_parser = require('properties-parser');
|
||||||
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
|
var AndroidStudio = require('./AndroidStudio');
|
||||||
|
var pluginHandlers = require('./pluginHandlers');
|
||||||
|
|
||||||
|
var projectFileCache = {};
|
||||||
|
|
||||||
|
function addToPropertyList (projectProperties, key, value) {
|
||||||
|
var i = 1;
|
||||||
|
while (projectProperties.get(key + '.' + i)) { i++; }
|
||||||
|
|
||||||
|
projectProperties.set(key + '.' + i, value);
|
||||||
|
projectProperties.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFromPropertyList (projectProperties, key, value) {
|
||||||
|
var i = 1;
|
||||||
|
var currentValue;
|
||||||
|
while ((currentValue = projectProperties.get(key + '.' + i))) {
|
||||||
|
if (currentValue === value) {
|
||||||
|
while ((currentValue = projectProperties.get(key + '.' + (i + 1)))) {
|
||||||
|
projectProperties.set(key + '.' + i, currentValue);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
projectProperties.set(key + '.' + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
projectProperties.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRelativeLibraryPath (parentDir, subDir) {
|
||||||
|
var libraryPath = path.relative(parentDir, subDir);
|
||||||
|
return (path.sep === '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AndroidProject (projectDir) {
|
||||||
|
this._propertiesEditors = {};
|
||||||
|
this._subProjectDirs = {};
|
||||||
|
this._dirty = false;
|
||||||
|
this.projectDir = projectDir;
|
||||||
|
this.platformWww = path.join(this.projectDir, 'platform_www');
|
||||||
|
this.www = path.join(this.projectDir, 'assets/www');
|
||||||
|
if (AndroidStudio.isAndroidStudioProject(projectDir) === true) {
|
||||||
|
this.www = path.join(this.projectDir, 'app/src/main/assets/www');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidProject.getProjectFile = function (projectDir) {
|
||||||
|
if (!projectFileCache[projectDir]) {
|
||||||
|
projectFileCache[projectDir] = new AndroidProject(projectDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectFileCache[projectDir];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.purgeCache = function (projectDir) {
|
||||||
|
if (projectDir) {
|
||||||
|
delete projectFileCache[projectDir];
|
||||||
|
} else {
|
||||||
|
projectFileCache = {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the package name out of the Android Manifest file
|
||||||
|
*
|
||||||
|
* @param {String} projectDir The absolute path to the directory containing the project
|
||||||
|
*
|
||||||
|
* @return {String} The name of the package
|
||||||
|
*/
|
||||||
|
AndroidProject.prototype.getPackageName = function () {
|
||||||
|
var manifestPath = path.join(this.projectDir, 'AndroidManifest.xml');
|
||||||
|
if (AndroidStudio.isAndroidStudioProject(this.projectDir) === true) {
|
||||||
|
manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
|
||||||
|
}
|
||||||
|
return new AndroidManifest(manifestPath).getPackageId();
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.getCustomSubprojectRelativeDir = function (plugin_id, src) {
|
||||||
|
// All custom subprojects are prefixed with the last portion of the package id.
|
||||||
|
// This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.
|
||||||
|
var packageName = this.getPackageName();
|
||||||
|
var lastDotIndex = packageName.lastIndexOf('.');
|
||||||
|
var prefix = packageName.substring(lastDotIndex + 1);
|
||||||
|
var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));
|
||||||
|
return subRelativeDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.addSubProject = function (parentDir, subDir) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var subProjectFile = path.resolve(subDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
// TODO: Setting the target needs to happen only for pre-3.7.0 projects
|
||||||
|
if (fs.existsSync(subProjectFile)) {
|
||||||
|
var subProperties = this._getPropertiesFile(subProjectFile);
|
||||||
|
subProperties.set('target', parentProperties.get('target'));
|
||||||
|
subProperties.dirty = true;
|
||||||
|
this._subProjectDirs[subDir] = true;
|
||||||
|
}
|
||||||
|
addToPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));
|
||||||
|
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.removeSubProject = function (parentDir, subDir) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));
|
||||||
|
delete this._subProjectDirs[subDir];
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.addGradleReference = function (parentDir, subDir) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.removeGradleReference = function (parentDir, subDir) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.addSystemLibrary = function (parentDir, value) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
addToPropertyList(parentProperties, 'cordova.system.library', value);
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.removeSystemLibrary = function (parentDir, value) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
removeFromPropertyList(parentProperties, 'cordova.system.library', value);
|
||||||
|
this._dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.write = function () {
|
||||||
|
if (!this._dirty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._dirty = false;
|
||||||
|
|
||||||
|
for (var filename in this._propertiesEditors) {
|
||||||
|
var editor = this._propertiesEditors[filename];
|
||||||
|
if (editor.dirty) {
|
||||||
|
fs.writeFileSync(filename, editor.toString());
|
||||||
|
editor.dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype._getPropertiesFile = function (filename) {
|
||||||
|
if (!this._propertiesEditors[filename]) {
|
||||||
|
if (fs.existsSync(filename)) {
|
||||||
|
this._propertiesEditors[filename] = properties_parser.createEditor(filename);
|
||||||
|
} else {
|
||||||
|
this._propertiesEditors[filename] = properties_parser.createEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._propertiesEditors[filename];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.getInstaller = function (type) {
|
||||||
|
return pluginHandlers.getInstaller(type);
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidProject.prototype.getUninstaller = function (type) {
|
||||||
|
return pluginHandlers.getUninstaller(type);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This checks if an Android project is clean or has old build artifacts
|
||||||
|
*/
|
||||||
|
|
||||||
|
AndroidProject.prototype.isClean = function () {
|
||||||
|
var build_path = path.join(this.projectDir, 'build');
|
||||||
|
// If the build directory doesn't exist, it's clean
|
||||||
|
return !(fs.existsSync(build_path));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = AndroidProject;
|
42
bin/templates/cordova/lib/AndroidStudio.js
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This is a simple routine that checks if project is an Android Studio Project
|
||||||
|
*
|
||||||
|
* @param {String} root Root folder of the project
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* jshint esnext: false */
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
|
var fs = require('fs');
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
|
module.exports.isAndroidStudioProject = function isAndroidStudioProject (root) {
|
||||||
|
var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res'];
|
||||||
|
var androidStudioFiles = ['app', 'app/src/main'];
|
||||||
|
|
||||||
|
// assume it is an AS project and not an Eclipse project
|
||||||
|
var isEclipse = false;
|
||||||
|
var isAS = true;
|
||||||
|
|
||||||
|
if (!fs.existsSync(root)) {
|
||||||
|
throw new CordovaError('AndroidStudio.js:inAndroidStudioProject root does not exist: ' + root);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if any of the following exists, then we are not an ASProj
|
||||||
|
eclipseFiles.forEach(function (file) {
|
||||||
|
if (fs.existsSync(path.join(root, file))) {
|
||||||
|
isEclipse = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// if it is NOT an eclipse project, check that all required files exist
|
||||||
|
if (!isEclipse) {
|
||||||
|
androidStudioFiles.forEach(function (file) {
|
||||||
|
if (!fs.existsSync(path.join(root, file))) {
|
||||||
|
console.log('missing file :: ' + file);
|
||||||
|
isAS = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return (!isEclipse && isAS);
|
||||||
|
};
|
@ -17,9 +17,10 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const execa = require('execa');
|
var Q = require('q');
|
||||||
|
var superspawn = require('cordova-common').superspawn;
|
||||||
|
|
||||||
const suffix_number_regex = /(\d+)$/;
|
var suffix_number_regex = /(\d+)$/;
|
||||||
// Used for sorting Android targets, example strings to sort:
|
// Used for sorting Android targets, example strings to sort:
|
||||||
// android-19
|
// android-19
|
||||||
// android-L
|
// android-L
|
||||||
@ -29,14 +30,17 @@ const suffix_number_regex = /(\d+)$/;
|
|||||||
// the number at the end, the more recent the target, the closer to the
|
// the number at the end, the more recent the target, the closer to the
|
||||||
// start of the array.
|
// start of the array.
|
||||||
function sort_by_largest_numerical_suffix (a, b) {
|
function sort_by_largest_numerical_suffix (a, b) {
|
||||||
let suffix_a = a.match(suffix_number_regex);
|
var suffix_a = a.match(suffix_number_regex);
|
||||||
let suffix_b = b.match(suffix_number_regex);
|
var suffix_b = b.match(suffix_number_regex);
|
||||||
// If no number is detected (eg: preview version like android-R),
|
if (suffix_a && suffix_b) {
|
||||||
// designate a suffix of 0 so it gets moved to the end
|
// If the two targets being compared have suffixes, return less than
|
||||||
suffix_a = suffix_a || ['0', '0'];
|
// zero, or greater than zero, based on which suffix is larger.
|
||||||
suffix_b = suffix_b || ['0', '0'];
|
|
||||||
// Return < zero, or > zero, based on which suffix is larger.
|
|
||||||
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
||||||
|
} else {
|
||||||
|
// If no suffix numbers were detected, leave the order as-is between
|
||||||
|
// elements a and b.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.print_newest_available_sdk_target = function () {
|
module.exports.print_newest_available_sdk_target = function () {
|
||||||
@ -46,8 +50,6 @@ module.exports.print_newest_available_sdk_target = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Versions should not be represented as float, so we disable quote-props here
|
|
||||||
/* eslint-disable quote-props */
|
|
||||||
module.exports.version_string_to_api_level = {
|
module.exports.version_string_to_api_level = {
|
||||||
'4.0': 14,
|
'4.0': 14,
|
||||||
'4.0.3': 15,
|
'4.0.3': 15,
|
||||||
@ -60,15 +62,13 @@ module.exports.version_string_to_api_level = {
|
|||||||
'5.1': 22,
|
'5.1': 22,
|
||||||
'6.0': 23,
|
'6.0': 23,
|
||||||
'7.0': 24,
|
'7.0': 24,
|
||||||
'7.1.1': 25,
|
'7.1.1': 25
|
||||||
'8.0': 26
|
|
||||||
};
|
};
|
||||||
/* eslint-enable quote-props */
|
|
||||||
|
|
||||||
function parse_targets (output) {
|
function parse_targets (output) {
|
||||||
const target_out = output.split('\n');
|
var target_out = output.split('\n');
|
||||||
const targets = [];
|
var targets = [];
|
||||||
for (let i = target_out.length - 1; i >= 0; i--) {
|
for (var i = target_out.length - 1; i >= 0; i--) {
|
||||||
if (target_out[i].match(/id:/)) { // if "id:" is in the line...
|
if (target_out[i].match(/id:/)) { // if "id:" is in the line...
|
||||||
targets.push(target_out[i].match(/"(.+)"/)[1]); // .. match whatever is in quotes.
|
targets.push(target_out[i].match(/"(.+)"/)[1]); // .. match whatever is in quotes.
|
||||||
}
|
}
|
||||||
@ -76,14 +76,25 @@ function parse_targets (output) {
|
|||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.list_targets_with_android = function () {
|
||||||
|
return superspawn.spawn('android', ['list', 'target']).then(parse_targets);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.list_targets_with_avdmanager = function () {
|
module.exports.list_targets_with_avdmanager = function () {
|
||||||
return execa('avdmanager', ['list', 'target']).then(result => parse_targets(result.stdout));
|
return superspawn.spawn('avdmanager', ['list', 'target']).then(parse_targets);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.list_targets = function () {
|
module.exports.list_targets = function () {
|
||||||
return module.exports.list_targets_with_avdmanager().then(function (targets) {
|
return module.exports.list_targets_with_avdmanager().catch(function (err) {
|
||||||
|
// If there's an error, like avdmanager could not be found, we can try
|
||||||
|
// as a last resort, to run `android`, in case this is a super old
|
||||||
|
// SDK installation.
|
||||||
|
if (err && (err.code === 'ENOENT' || (err.stderr && err.stderr.match(/not recognized/)))) {
|
||||||
|
return module.exports.list_targets_with_android();
|
||||||
|
} else throw err;
|
||||||
|
}).then(function (targets) {
|
||||||
if (targets.length === 0) {
|
if (targets.length === 0) {
|
||||||
return Promise.reject(new Error('No android targets (SDKs) installed!'));
|
return Q.reject(new Error('No android targets (SDKs) installed!'));
|
||||||
}
|
}
|
||||||
return targets;
|
return targets;
|
||||||
});
|
});
|
294
bin/templates/cordova/lib/build.js
vendored
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var path = require('path');
|
||||||
|
var fs = require('fs');
|
||||||
|
var nopt = require('nopt');
|
||||||
|
|
||||||
|
var Adb = require('./Adb');
|
||||||
|
|
||||||
|
var builders = require('./builders/builders');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
var spawn = require('cordova-common').superspawn.spawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
|
function parseOpts (options, resolvedTarget, projectRoot) {
|
||||||
|
options = options || {};
|
||||||
|
options.argv = nopt({
|
||||||
|
gradle: Boolean,
|
||||||
|
studio: Boolean,
|
||||||
|
prepenv: Boolean,
|
||||||
|
versionCode: String,
|
||||||
|
minSdkVersion: String,
|
||||||
|
gradleArg: [String, Array],
|
||||||
|
keystore: path,
|
||||||
|
alias: String,
|
||||||
|
storePassword: String,
|
||||||
|
password: String,
|
||||||
|
keystoreType: String
|
||||||
|
}, {}, options.argv, 0);
|
||||||
|
|
||||||
|
// Android Studio Build method is the default
|
||||||
|
var ret = {
|
||||||
|
buildType: options.release ? 'release' : 'debug',
|
||||||
|
buildMethod: process.env.ANDROID_BUILD || 'studio',
|
||||||
|
prepEnv: options.argv.prepenv,
|
||||||
|
arch: resolvedTarget && resolvedTarget.arch,
|
||||||
|
extraArgs: []
|
||||||
|
};
|
||||||
|
|
||||||
|
if (options.argv.gradle || options.argv.studio) {
|
||||||
|
ret.buildMethod = options.argv.studio ? 'studio' : 'gradle';
|
||||||
|
}
|
||||||
|
|
||||||
|
// This comes from cordova/run
|
||||||
|
if (options.studio) ret.buildMethod = 'studio';
|
||||||
|
if (options.gradle) ret.buildMethod = 'gradle';
|
||||||
|
|
||||||
|
if (options.nobuild) ret.buildMethod = 'none';
|
||||||
|
|
||||||
|
if (options.argv.versionCode) { ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode); }
|
||||||
|
|
||||||
|
if (options.argv.minSdkVersion) { ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion); }
|
||||||
|
|
||||||
|
if (options.argv.gradleArg) {
|
||||||
|
ret.extraArgs = ret.extraArgs.concat(options.argv.gradleArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageArgs = {};
|
||||||
|
|
||||||
|
if (options.argv.keystore) { packageArgs.keystore = path.relative(projectRoot, path.resolve(options.argv.keystore)); }
|
||||||
|
|
||||||
|
['alias', 'storePassword', 'password', 'keystoreType'].forEach(function (flagName) {
|
||||||
|
if (options.argv[flagName]) { packageArgs[flagName] = options.argv[flagName]; }
|
||||||
|
});
|
||||||
|
|
||||||
|
var buildConfig = options.buildConfig;
|
||||||
|
|
||||||
|
// If some values are not specified as command line arguments - use build config to supplement them.
|
||||||
|
// Command line arguemnts have precedence over build config.
|
||||||
|
if (buildConfig) {
|
||||||
|
if (!fs.existsSync(buildConfig)) {
|
||||||
|
throw new Error('Specified build config file does not exist: ' + buildConfig);
|
||||||
|
}
|
||||||
|
events.emit('log', 'Reading build config file: ' + path.resolve(buildConfig));
|
||||||
|
var buildjson = fs.readFileSync(buildConfig, 'utf8');
|
||||||
|
var config = JSON.parse(buildjson.replace(/^\ufeff/, '')); // Remove BOM
|
||||||
|
if (config.android && config.android[ret.buildType]) {
|
||||||
|
var androidInfo = config.android[ret.buildType];
|
||||||
|
if (androidInfo.keystore && !packageArgs.keystore) {
|
||||||
|
if (androidInfo.keystore.substr(0, 1) === '~') {
|
||||||
|
androidInfo.keystore = process.env.HOME + androidInfo.keystore.substr(1);
|
||||||
|
}
|
||||||
|
packageArgs.keystore = path.resolve(path.dirname(buildConfig), androidInfo.keystore);
|
||||||
|
events.emit('log', 'Reading the keystore from: ' + packageArgs.keystore);
|
||||||
|
}
|
||||||
|
|
||||||
|
['alias', 'storePassword', 'password', 'keystoreType'].forEach(function (key) {
|
||||||
|
packageArgs[key] = packageArgs[key] || androidInfo[key];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageArgs.keystore && packageArgs.alias) {
|
||||||
|
ret.packageInfo = new PackageInfo(packageArgs.keystore, packageArgs.alias, packageArgs.storePassword,
|
||||||
|
packageArgs.password, packageArgs.keystoreType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret.packageInfo) {
|
||||||
|
if (Object.keys(packageArgs).length > 0) {
|
||||||
|
events.emit('warn', '\'keystore\' and \'alias\' need to be specified to generate a signed archive.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Builds the project with the specifed options
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.runClean = function (options) {
|
||||||
|
var opts = parseOpts(options, null, this.root);
|
||||||
|
var builder = builders.getBuilder(opts.buildMethod);
|
||||||
|
return builder.prepEnv(opts).then(function () {
|
||||||
|
return builder.clean(opts);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the project with the specifed options.
|
||||||
|
*
|
||||||
|
* @param {BuildOptions} options A set of options. See PlatformApi.build
|
||||||
|
* method documentation for reference.
|
||||||
|
* @param {Object} optResolvedTarget A deployment target. Used to pass
|
||||||
|
* target architecture from upstream 'run' call. TODO: remove this option in
|
||||||
|
* favor of setting buildOptions.archs field.
|
||||||
|
*
|
||||||
|
* @return {Promise<Object>} Promise, resolved with built packages
|
||||||
|
* information.
|
||||||
|
*/
|
||||||
|
module.exports.run = function (options, optResolvedTarget) {
|
||||||
|
var opts = parseOpts(options, optResolvedTarget, this.root);
|
||||||
|
console.log(opts.buildMethod);
|
||||||
|
var builder = builders.getBuilder(opts.buildMethod);
|
||||||
|
return builder.prepEnv(opts).then(function () {
|
||||||
|
if (opts.prepEnv) {
|
||||||
|
events.emit('verbose', 'Build file successfully prepared.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return builder.build(opts).then(function () {
|
||||||
|
var apkPaths = builder.findOutputApks(opts.buildType, opts.arch);
|
||||||
|
events.emit('log', 'Built the following apk(s): \n\t' + apkPaths.join('\n\t'));
|
||||||
|
return {
|
||||||
|
apkPaths: apkPaths,
|
||||||
|
buildType: opts.buildType,
|
||||||
|
buildMethod: opts.buildMethod
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Detects the architecture of a device/emulator
|
||||||
|
* Returns "arm" or "x86".
|
||||||
|
*/
|
||||||
|
module.exports.detectArchitecture = function (target) {
|
||||||
|
function helper () {
|
||||||
|
return Adb.shell(target, 'cat /proc/cpuinfo').then(function (output) {
|
||||||
|
return /intel/i.exec(output) ? 'x86' : 'arm';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// It sometimes happens (at least on OS X), that this command will hang forever.
|
||||||
|
// To fix it, either unplug & replug device, or restart adb server.
|
||||||
|
return helper().timeout(1000, new CordovaError('Device communication timed out. Try unplugging & replugging the device.')).then(null, function (err) {
|
||||||
|
if (/timed out/.exec('' + err)) {
|
||||||
|
// adb kill-server doesn't seem to do the trick.
|
||||||
|
// Could probably find a x-platform version of killall, but I'm not actually
|
||||||
|
// sure that this scenario even happens on non-OSX machines.
|
||||||
|
events.emit('verbose', 'adb timed out while detecting device/emulator architecture. Killing adb and trying again.');
|
||||||
|
return spawn('killall', ['adb']).then(function () {
|
||||||
|
return helper().then(null, function () {
|
||||||
|
// The double kill is sadly often necessary, at least on mac.
|
||||||
|
events.emit('warn', 'adb timed out a second time while detecting device/emulator architecture. Killing adb and trying again.');
|
||||||
|
return spawn('killall', ['adb']).then(function () {
|
||||||
|
return helper().then(null, function () {
|
||||||
|
return Q.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, function () {
|
||||||
|
// For non-killall OS's.
|
||||||
|
return Q.reject(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.findBestApkForArchitecture = function (buildResults, arch) {
|
||||||
|
var paths = buildResults.apkPaths.filter(function (p) {
|
||||||
|
var apkName = path.basename(p);
|
||||||
|
if (buildResults.buildType === 'debug') {
|
||||||
|
return /-debug/.exec(apkName);
|
||||||
|
}
|
||||||
|
return !/-debug/.exec(apkName);
|
||||||
|
});
|
||||||
|
var archPattern = new RegExp('-' + arch);
|
||||||
|
var hasArchPattern = /-x86|-arm/;
|
||||||
|
for (var i = 0; i < paths.length; ++i) {
|
||||||
|
var apkName = path.basename(paths[i]);
|
||||||
|
if (hasArchPattern.exec(apkName)) {
|
||||||
|
if (archPattern.exec(apkName)) {
|
||||||
|
return paths[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return paths[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error('Could not find apk architecture: ' + arch + ' build-type: ' + buildResults.buildType);
|
||||||
|
};
|
||||||
|
|
||||||
|
function PackageInfo (keystore, alias, storePassword, password, keystoreType) {
|
||||||
|
this.keystore = {
|
||||||
|
'name': 'key.store',
|
||||||
|
'value': keystore
|
||||||
|
};
|
||||||
|
this.alias = {
|
||||||
|
'name': 'key.alias',
|
||||||
|
'value': alias
|
||||||
|
};
|
||||||
|
if (storePassword) {
|
||||||
|
this.storePassword = {
|
||||||
|
'name': 'key.store.password',
|
||||||
|
'value': storePassword
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (password) {
|
||||||
|
this.password = {
|
||||||
|
'name': 'key.alias.password',
|
||||||
|
'value': password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (keystoreType) {
|
||||||
|
this.keystoreType = {
|
||||||
|
'name': 'key.store.type',
|
||||||
|
'value': keystoreType
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageInfo.prototype = {
|
||||||
|
toProperties: function () {
|
||||||
|
var self = this;
|
||||||
|
var result = '';
|
||||||
|
Object.keys(self).forEach(function (key) {
|
||||||
|
result += self[key].name;
|
||||||
|
result += '=';
|
||||||
|
result += self[key].value.replace(/\\/g, '\\\\');
|
||||||
|
result += '\n';
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.help = function () {
|
||||||
|
console.log('Usage: ' + path.relative(process.cwd(), path.join('../build')) + ' [flags] [Signed APK flags]');
|
||||||
|
console.log('Flags:');
|
||||||
|
console.log(' \'--debug\': will build project in debug mode (default)');
|
||||||
|
console.log(' \'--release\': will build project for release');
|
||||||
|
console.log(' \'--ant\': will build project with ant');
|
||||||
|
console.log(' \'--gradle\': will build project with gradle (default)');
|
||||||
|
console.log(' \'--nobuild\': will skip build process (useful when using run command)');
|
||||||
|
console.log(' \'--prepenv\': don\'t build, but copy in build scripts where necessary');
|
||||||
|
console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs. Requires --gradle.');
|
||||||
|
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs. Requires --gradle.');
|
||||||
|
console.log(' \'--gradleArg=<gradle command line arg>\': Extra args to pass to the gradle command. Use one flag per arg. Ex. --gradleArg=-PcdvBuildMultipleApks=true');
|
||||||
|
console.log('');
|
||||||
|
console.log('Signed APK flags (overwrites debug/release-signing.proprties) :');
|
||||||
|
console.log(' \'--keystore=<path to keystore>\': Key store used to build a signed archive. (Required)');
|
||||||
|
console.log(' \'--alias=\': Alias for the key store. (Required)');
|
||||||
|
console.log(' \'--storePassword=\': Password for the key store. (Optional - prompted)');
|
||||||
|
console.log(' \'--password=\': Password for the key. (Optional - prompted)');
|
||||||
|
console.log(' \'--keystoreType\': Type of the keystore. (Optional)');
|
||||||
|
process.exit(0);
|
||||||
|
};
|
124
bin/templates/cordova/lib/builders/GenericBuilder.js
vendored
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
/* eslint no-self-assign: 0 */
|
||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
|
||||||
|
function GenericBuilder (projectDir) {
|
||||||
|
this.root = projectDir || path.resolve(__dirname, '../../..');
|
||||||
|
this.binDirs = {
|
||||||
|
studio: path.join(this.root, 'app', 'build', 'outputs', 'apk'),
|
||||||
|
gradle: path.join(this.root, 'build', 'outputs', 'apk')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GenericBuilder.prototype.prepEnv = function () {
|
||||||
|
return Q();
|
||||||
|
};
|
||||||
|
|
||||||
|
GenericBuilder.prototype.build = function () {
|
||||||
|
events.emit('log', 'Skipping build...');
|
||||||
|
return Q(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
GenericBuilder.prototype.clean = function () {
|
||||||
|
return Q();
|
||||||
|
};
|
||||||
|
|
||||||
|
GenericBuilder.prototype.findOutputApks = function (build_type, arch) {
|
||||||
|
var self = this;
|
||||||
|
return Object.keys(this.binDirs).reduce(function (result, builderName) {
|
||||||
|
var binDir = self.binDirs[builderName];
|
||||||
|
return result.concat(findOutputApksHelper(binDir, build_type, builderName === 'ant' ? null : arch));
|
||||||
|
}, []).sort(apkSorter);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GenericBuilder;
|
||||||
|
|
||||||
|
function apkSorter (fileA, fileB) {
|
||||||
|
// De-prioritize arch specific builds
|
||||||
|
var archSpecificRE = /-x86|-arm/;
|
||||||
|
if (archSpecificRE.exec(fileA)) {
|
||||||
|
return 1;
|
||||||
|
} else if (archSpecificRE.exec(fileB)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-prioritize unsigned builds
|
||||||
|
var unsignedRE = /-unsigned/;
|
||||||
|
if (unsignedRE.exec(fileA)) {
|
||||||
|
return 1;
|
||||||
|
} else if (unsignedRE.exec(fileB)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var timeDiff = fs.statSync(fileB).mtime - fs.statSync(fileA).mtime;
|
||||||
|
return timeDiff === 0 ? fileA.length - fileB.length : timeDiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findOutputApksHelper (dir, build_type, arch) {
|
||||||
|
var shellSilent = shell.config.silent;
|
||||||
|
shell.config.silent = true;
|
||||||
|
|
||||||
|
// list directory recursively
|
||||||
|
var ret = shell.ls('-R', dir).map(function (file) {
|
||||||
|
// ls does not include base directory
|
||||||
|
return path.join(dir, file);
|
||||||
|
}).filter(function (file) {
|
||||||
|
// find all APKs
|
||||||
|
return file.match(/\.apk?$/i);
|
||||||
|
}).filter(function (candidate) {
|
||||||
|
var apkName = path.basename(candidate);
|
||||||
|
// Need to choose between release and debug .apk.
|
||||||
|
if (build_type === 'debug') {
|
||||||
|
return /-debug/.exec(apkName) && !/-unaligned|-unsigned/.exec(apkName);
|
||||||
|
}
|
||||||
|
if (build_type === 'release') {
|
||||||
|
return /-release/.exec(apkName) && !/-unaligned/.exec(apkName);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).sort(apkSorter);
|
||||||
|
|
||||||
|
shellSilent = shellSilent;
|
||||||
|
|
||||||
|
if (ret.length === 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
// Assume arch-specific build if newest apk has -x86 or -arm.
|
||||||
|
var archSpecific = !!/-x86|-arm/.exec(path.basename(ret[0]));
|
||||||
|
// And show only arch-specific ones (or non-arch-specific)
|
||||||
|
ret = ret.filter(function (p) {
|
||||||
|
/* jshint -W018 */
|
||||||
|
return !!/-x86|-arm/.exec(path.basename(p)) === archSpecific;
|
||||||
|
/* jshint +W018 */
|
||||||
|
});
|
||||||
|
|
||||||
|
if (archSpecific && ret.length > 1 && arch) {
|
||||||
|
ret = ret.filter(function (p) {
|
||||||
|
return path.basename(p).indexOf('-' + arch) !== -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
330
bin/templates/cordova/lib/builders/GradleBuilder.js
vendored
Normal file
@ -0,0 +1,330 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var fs = require('fs');
|
||||||
|
var util = require('util');
|
||||||
|
var path = require('path');
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var superspawn = require('cordova-common').superspawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var check_reqs = require('../check_reqs');
|
||||||
|
|
||||||
|
var GenericBuilder = require('./GenericBuilder');
|
||||||
|
|
||||||
|
var MARKER = 'YOUR CHANGES WILL BE ERASED!';
|
||||||
|
var SIGNING_PROPERTIES = '-signing.properties';
|
||||||
|
var TEMPLATE =
|
||||||
|
'# This file is automatically generated.\n' +
|
||||||
|
'# Do not modify this file -- ' + MARKER + '\n';
|
||||||
|
|
||||||
|
function GradleBuilder (projectRoot) {
|
||||||
|
GenericBuilder.call(this, projectRoot);
|
||||||
|
|
||||||
|
this.binDirs = { gradle: this.binDirs.gradle };
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(GradleBuilder, GenericBuilder);
|
||||||
|
|
||||||
|
GradleBuilder.prototype.getArgs = function (cmd, opts) {
|
||||||
|
if (cmd === 'release') {
|
||||||
|
cmd = 'cdvBuildRelease';
|
||||||
|
} else if (cmd === 'debug') {
|
||||||
|
cmd = 'cdvBuildDebug';
|
||||||
|
}
|
||||||
|
var args = [cmd, '-b', path.join(this.root, 'build.gradle')];
|
||||||
|
if (opts.arch) {
|
||||||
|
args.push('-PcdvBuildArch=' + opts.arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 10 seconds -> 6 seconds
|
||||||
|
args.push('-Dorg.gradle.daemon=true');
|
||||||
|
// to allow dex in process
|
||||||
|
args.push('-Dorg.gradle.jvmargs=-Xmx2048m');
|
||||||
|
// allow NDK to be used - required by Gradle 1.5 plugin
|
||||||
|
args.push('-Pandroid.useDeprecatedNdk=true');
|
||||||
|
args.push.apply(args, opts.extraArgs);
|
||||||
|
// Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
|
||||||
|
// args.push('-Dorg.gradle.parallel=true');
|
||||||
|
return args;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This returns a promise
|
||||||
|
*/
|
||||||
|
|
||||||
|
GradleBuilder.prototype.runGradleWrapper = function (gradle_cmd, gradle_file) {
|
||||||
|
var gradlePath = path.join(this.root, 'gradlew');
|
||||||
|
gradle_file = path.join(this.root, (gradle_file || 'wrapper.gradle'));
|
||||||
|
if (fs.existsSync(gradlePath)) {
|
||||||
|
// Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
|
||||||
|
} else {
|
||||||
|
return superspawn.spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', gradle_file], { stdio: 'pipe' })
|
||||||
|
.progress(function (stdio) {
|
||||||
|
suppressJavaOptionsInfo(stdio);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to kill this in a fire.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GradleBuilder.prototype.readProjectProperties = function () {
|
||||||
|
function findAllUniq (data, r) {
|
||||||
|
var s = {};
|
||||||
|
var m;
|
||||||
|
while ((m = r.exec(data))) {
|
||||||
|
s[m[1]] = 1;
|
||||||
|
}
|
||||||
|
return Object.keys(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = fs.readFileSync(path.join(this.root, 'project.properties'), 'utf8');
|
||||||
|
return {
|
||||||
|
libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
|
||||||
|
gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
|
||||||
|
systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
GradleBuilder.prototype.extractRealProjectNameFromManifest = function () {
|
||||||
|
var manifestPath = path.join(this.root, 'AndroidManifest.xml');
|
||||||
|
var manifestData = fs.readFileSync(manifestPath, 'utf8');
|
||||||
|
var m = /<manifest[\s\S]*?package\s*=\s*"(.*?)"/i.exec(manifestData);
|
||||||
|
if (!m) {
|
||||||
|
throw new CordovaError('Could not find package name in ' + manifestPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageName = m[1];
|
||||||
|
var lastDotIndex = packageName.lastIndexOf('.');
|
||||||
|
return packageName.substring(lastDotIndex + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Makes the project buildable, minus the gradle wrapper.
|
||||||
|
GradleBuilder.prototype.prepBuildFiles = function () {
|
||||||
|
// Update the version of build.gradle in each dependent library.
|
||||||
|
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
|
||||||
|
var propertiesObj = this.readProjectProperties();
|
||||||
|
var subProjects = propertiesObj.libs;
|
||||||
|
|
||||||
|
// Check and copy the gradle file into the subproject.
|
||||||
|
// Called by the loop below this function def.
|
||||||
|
var checkAndCopy = function (subProject, root) {
|
||||||
|
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
||||||
|
// This is the future-proof way of checking if a file exists
|
||||||
|
// This must be synchronous to satisfy a Travis test
|
||||||
|
try {
|
||||||
|
fs.accessSync(subProjectGradle, fs.F_OK);
|
||||||
|
} catch (e) {
|
||||||
|
shell.cp('-f', pluginBuildGradle, subProjectGradle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Some dependencies on Android don't use gradle, or don't have default
|
||||||
|
// gradle files. This copies a dummy gradle file into them
|
||||||
|
for (var i = 0; i < subProjects.length; ++i) {
|
||||||
|
if (subProjects[i] !== 'CordovaLib' && subProjects[i] !== 'app') {
|
||||||
|
checkAndCopy(subProjects[i], this.root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = this.extractRealProjectNameFromManifest();
|
||||||
|
// Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
||||||
|
var settingsGradlePaths = subProjects.map(function (p) {
|
||||||
|
var realDir = p.replace(/[/\\]/g, ':');
|
||||||
|
var libName = realDir.replace(name + '-', '');
|
||||||
|
var str = 'include ":' + libName + '"\n';
|
||||||
|
if (realDir.indexOf(name + '-') !== -1) { str += 'project(":' + libName + '").projectDir = new File("' + p + '")\n'; }
|
||||||
|
return str;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Write the settings.gradle file.
|
||||||
|
fs.writeFileSync(path.join(this.root, 'settings.gradle'),
|
||||||
|
'// GENERATED FILE - DO NOT EDIT\n' +
|
||||||
|
'include ":"\n' + settingsGradlePaths.join(''));
|
||||||
|
// Update dependencies within build.gradle.
|
||||||
|
var buildGradle = fs.readFileSync(path.join(this.root, 'build.gradle'), 'utf8');
|
||||||
|
var depsList = '';
|
||||||
|
var root = this.root;
|
||||||
|
|
||||||
|
// Cordova Plugins can be written as library modules that would use Cordova as a
|
||||||
|
// dependency. Because we need to make sure that Cordova is compiled only once for
|
||||||
|
// dexing, we make sure to exclude CordovaLib from these modules
|
||||||
|
var insertExclude = function (p) {
|
||||||
|
var gradlePath = path.join(root, p, 'build.gradle');
|
||||||
|
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
||||||
|
if (projectGradleFile.indexOf('CordovaLib') !== -1) {
|
||||||
|
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
||||||
|
} else {
|
||||||
|
depsList += '\n';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
subProjects.forEach(function (p) {
|
||||||
|
console.log('Subproject Path: ' + p);
|
||||||
|
var libName = p.replace(/[/\\]/g, ':').replace(name + '-', '');
|
||||||
|
depsList += ' implementation(project(path: "' + libName + '"))';
|
||||||
|
insertExclude(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
// For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
|
||||||
|
var SYSTEM_LIBRARY_MAPPINGS = [
|
||||||
|
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
||||||
|
[/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']
|
||||||
|
];
|
||||||
|
propertiesObj.systemLibs.forEach(function (p) {
|
||||||
|
var mavenRef;
|
||||||
|
// It's already in gradle form if it has two ':'s
|
||||||
|
if (/:.*:/.exec(p)) {
|
||||||
|
mavenRef = p;
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < SYSTEM_LIBRARY_MAPPINGS.length; ++i) {
|
||||||
|
var pair = SYSTEM_LIBRARY_MAPPINGS[i];
|
||||||
|
if (pair[0].exec(p)) {
|
||||||
|
mavenRef = p.replace(pair[0], pair[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mavenRef) {
|
||||||
|
throw new CordovaError('Unsupported system library (does not work with gradle): ' + p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
depsList += ' compile "' + mavenRef + '"\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
// This code is dangerous and actually writes gradle declarations directly into the build.gradle
|
||||||
|
// Try not to mess with this if possible
|
||||||
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
||||||
|
var includeList = '';
|
||||||
|
propertiesObj.gradleIncludes.forEach(function (includePath) {
|
||||||
|
includeList += 'apply from: "' + includePath + '"\n';
|
||||||
|
});
|
||||||
|
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + includeList + '$2');
|
||||||
|
fs.writeFileSync(path.join(this.root, 'build.gradle'), buildGradle);
|
||||||
|
};
|
||||||
|
|
||||||
|
GradleBuilder.prototype.prepEnv = function (opts) {
|
||||||
|
var self = this;
|
||||||
|
return check_reqs.check_gradle().then(function (gradlePath) {
|
||||||
|
return self.runGradleWrapper(gradlePath);
|
||||||
|
}).then(function () {
|
||||||
|
return self.prepBuildFiles();
|
||||||
|
}).then(function () {
|
||||||
|
// We now copy the gradle out of the framework
|
||||||
|
// This is a dirty patch to get the build working
|
||||||
|
/*
|
||||||
|
var wrapperDir = path.join(self.root, 'CordovaLib');
|
||||||
|
if (process.platform == 'win32') {
|
||||||
|
shell.rm('-f', path.join(self.root, 'gradlew.bat'));
|
||||||
|
shell.cp(path.join(wrapperDir, 'gradlew.bat'), self.root);
|
||||||
|
} else {
|
||||||
|
shell.rm('-f', path.join(self.root, 'gradlew'));
|
||||||
|
shell.cp(path.join(wrapperDir, 'gradlew'), self.root);
|
||||||
|
}
|
||||||
|
shell.rm('-rf', path.join(self.root, 'gradle', 'wrapper'));
|
||||||
|
shell.mkdir('-p', path.join(self.root, 'gradle'));
|
||||||
|
shell.cp('-r', path.join(wrapperDir, 'gradle', 'wrapper'), path.join(self.root, 'gradle'));
|
||||||
|
*/
|
||||||
|
// If the gradle distribution URL is set, make sure it points to version we want.
|
||||||
|
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
||||||
|
// For some reason, using ^ and $ don't work. This does the job, though.
|
||||||
|
var distributionUrlRegex = /distributionUrl.*zip/;
|
||||||
|
/* jshint -W069 */
|
||||||
|
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
|
||||||
|
/* jshint +W069 */
|
||||||
|
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
||||||
|
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
||||||
|
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
|
||||||
|
|
||||||
|
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
||||||
|
var propertiesFilePath = path.join(self.root, propertiesFile);
|
||||||
|
if (opts.packageInfo) {
|
||||||
|
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
||||||
|
} else if (isAutoGenerated(propertiesFilePath)) {
|
||||||
|
shell.rm('-f', propertiesFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Builds the project with gradle.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
GradleBuilder.prototype.build = function (opts) {
|
||||||
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
|
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
||||||
|
|
||||||
|
return superspawn.spawn(wrapper, args, { stdio: 'pipe' })
|
||||||
|
.progress(function (stdio) {
|
||||||
|
suppressJavaOptionsInfo(stdio);
|
||||||
|
}).catch(function (error) {
|
||||||
|
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
||||||
|
return check_reqs.check_android_target(error).then(function () {
|
||||||
|
// If due to some odd reason - check_android_target succeeds
|
||||||
|
// we should still fail here.
|
||||||
|
return Q.reject(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Q.reject(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
GradleBuilder.prototype.clean = function (opts) {
|
||||||
|
var builder = this;
|
||||||
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
|
var args = builder.getArgs('clean', opts);
|
||||||
|
return Q().then(function () {
|
||||||
|
return superspawn.spawn(wrapper, args, { stdio: 'inherit' });
|
||||||
|
}).then(function () {
|
||||||
|
shell.rm('-rf', path.join(builder.root, 'out'));
|
||||||
|
|
||||||
|
['debug', 'release'].forEach(function (config) {
|
||||||
|
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
||||||
|
if (isAutoGenerated(propertiesFilePath)) {
|
||||||
|
shell.rm('-f', propertiesFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GradleBuilder;
|
||||||
|
|
||||||
|
function suppressJavaOptionsInfo (stdio) {
|
||||||
|
if (stdio.stderr) {
|
||||||
|
/*
|
||||||
|
* Workaround for the issue with Java printing some unwanted information to
|
||||||
|
* stderr instead of stdout.
|
||||||
|
* This function suppresses 'Picked up _JAVA_OPTIONS' message from being
|
||||||
|
* printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
|
||||||
|
* explanation.
|
||||||
|
*/
|
||||||
|
var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
|
||||||
|
if (suppressThisLine) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
process.stderr.write(stdio.stderr);
|
||||||
|
} else {
|
||||||
|
process.stdout.write(stdio.stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAutoGenerated (file) {
|
||||||
|
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
|
||||||
|
}
|
302
bin/templates/cordova/lib/builders/StudioBuilder.js
vendored
Normal file
@ -0,0 +1,302 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var fs = require('fs');
|
||||||
|
var util = require('util');
|
||||||
|
var path = require('path');
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var spawn = require('cordova-common').superspawn.spawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var check_reqs = require('../check_reqs');
|
||||||
|
|
||||||
|
var GenericBuilder = require('./GenericBuilder');
|
||||||
|
|
||||||
|
var MARKER = 'YOUR CHANGES WILL BE ERASED!';
|
||||||
|
var SIGNING_PROPERTIES = '-signing.properties';
|
||||||
|
var TEMPLATE =
|
||||||
|
'# This file is automatically generated.\n' +
|
||||||
|
'# Do not modify this file -- ' + MARKER + '\n';
|
||||||
|
|
||||||
|
function StudioBuilder (projectRoot) {
|
||||||
|
GenericBuilder.call(this, projectRoot);
|
||||||
|
|
||||||
|
this.binDirs = {gradle: this.binDirs.studio};
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(StudioBuilder, GenericBuilder);
|
||||||
|
|
||||||
|
StudioBuilder.prototype.getArgs = function (cmd, opts) {
|
||||||
|
if (cmd === 'release') {
|
||||||
|
cmd = 'cdvBuildRelease';
|
||||||
|
} else if (cmd === 'debug') {
|
||||||
|
cmd = 'cdvBuildDebug';
|
||||||
|
}
|
||||||
|
var args = [cmd, '-b', path.join(this.root, 'build.gradle')];
|
||||||
|
if (opts.arch) {
|
||||||
|
args.push('-PcdvBuildArch=' + opts.arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 10 seconds -> 6 seconds
|
||||||
|
args.push('-Dorg.gradle.daemon=true');
|
||||||
|
// to allow dex in process
|
||||||
|
args.push('-Dorg.gradle.jvmargs=-Xmx2048m');
|
||||||
|
// allow NDK to be used - required by Gradle 1.5 plugin
|
||||||
|
args.push('-Pandroid.useDeprecatedNdk=true');
|
||||||
|
args.push.apply(args, opts.extraArgs);
|
||||||
|
// Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
|
||||||
|
// args.push('-Dorg.gradle.parallel=true');
|
||||||
|
return args;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This returns a promise
|
||||||
|
*/
|
||||||
|
|
||||||
|
StudioBuilder.prototype.runGradleWrapper = function (gradle_cmd) {
|
||||||
|
var gradlePath = path.join(this.root, 'gradlew');
|
||||||
|
var wrapperGradle = path.join(this.root, 'wrapper.gradle');
|
||||||
|
if (fs.existsSync(gradlePath)) {
|
||||||
|
// Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
|
||||||
|
} else {
|
||||||
|
return spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioBuilder.prototype.readProjectProperties = function () {
|
||||||
|
|
||||||
|
function findAllUniq (data, r) {
|
||||||
|
var s = {};
|
||||||
|
var m;
|
||||||
|
while ((m = r.exec(data))) {
|
||||||
|
s[m[1]] = 1;
|
||||||
|
}
|
||||||
|
return Object.keys(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = fs.readFileSync(path.join(this.root, 'project.properties'), 'utf8');
|
||||||
|
return {
|
||||||
|
libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
|
||||||
|
gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
|
||||||
|
systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioBuilder.prototype.extractRealProjectNameFromManifest = function () {
|
||||||
|
var manifestPath = path.join(this.root, 'app', 'src', 'main', 'AndroidManifest.xml');
|
||||||
|
var manifestData = fs.readFileSync(manifestPath, 'utf8');
|
||||||
|
var m = /<manifest[\s\S]*?package\s*=\s*"(.*?)"/i.exec(manifestData);
|
||||||
|
if (!m) {
|
||||||
|
throw new CordovaError('Could not find package name in ' + manifestPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageName = m[1];
|
||||||
|
var lastDotIndex = packageName.lastIndexOf('.');
|
||||||
|
return packageName.substring(lastDotIndex + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Makes the project buildable, minus the gradle wrapper.
|
||||||
|
StudioBuilder.prototype.prepBuildFiles = function () {
|
||||||
|
// Update the version of build.gradle in each dependent library.
|
||||||
|
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
|
||||||
|
var propertiesObj = this.readProjectProperties();
|
||||||
|
var subProjects = propertiesObj.libs;
|
||||||
|
|
||||||
|
// Check and copy the gradle file into the subproject
|
||||||
|
// Called by the loop before this function def
|
||||||
|
|
||||||
|
var checkAndCopy = function (subProject, root) {
|
||||||
|
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
||||||
|
// This is the future-proof way of checking if a file exists
|
||||||
|
// This must be synchronous to satisfy a Travis test
|
||||||
|
try {
|
||||||
|
fs.accessSync(subProjectGradle, fs.F_OK);
|
||||||
|
} catch (e) {
|
||||||
|
shell.cp('-f', pluginBuildGradle, subProjectGradle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < subProjects.length; ++i) {
|
||||||
|
if (subProjects[i] !== 'CordovaLib') {
|
||||||
|
checkAndCopy(subProjects[i], this.root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var name = this.extractRealProjectNameFromManifest();
|
||||||
|
// Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
||||||
|
var settingsGradlePaths = subProjects.map(function (p) {
|
||||||
|
var realDir = p.replace(/[/\\]/g, ':');
|
||||||
|
var libName = realDir.replace(name + '-', '');
|
||||||
|
var str = 'include ":' + libName + '"\n';
|
||||||
|
if (realDir.indexOf(name + '-') !== -1) {
|
||||||
|
str += 'project(":' + libName + '").projectDir = new File("' + p + '")\n';
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(this.root, 'settings.gradle'),
|
||||||
|
'// GENERATED FILE - DO NOT EDIT\n' +
|
||||||
|
'include ":"\n' + settingsGradlePaths.join(''));
|
||||||
|
|
||||||
|
// Update dependencies within build.gradle.
|
||||||
|
var buildGradle = fs.readFileSync(path.join(this.root, 'app', 'build.gradle'), 'utf8');
|
||||||
|
var depsList = '';
|
||||||
|
var root = this.root;
|
||||||
|
var insertExclude = function (p) {
|
||||||
|
var gradlePath = path.join(root, p, 'build.gradle');
|
||||||
|
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
||||||
|
if (projectGradleFile.indexOf('CordovaLib') !== -1) {
|
||||||
|
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
||||||
|
} else {
|
||||||
|
depsList += '\n';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
subProjects.forEach(function (p) {
|
||||||
|
console.log('Subproject Path: ' + p);
|
||||||
|
var libName = p.replace(/[/\\]/g, ':').replace(name + '-', '');
|
||||||
|
if (libName !== 'app') {
|
||||||
|
depsList += ' implementation(project(path: ":' + libName + '"))';
|
||||||
|
insertExclude(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
|
||||||
|
var SYSTEM_LIBRARY_MAPPINGS = [
|
||||||
|
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
||||||
|
[/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']
|
||||||
|
];
|
||||||
|
|
||||||
|
propertiesObj.systemLibs.forEach(function (p) {
|
||||||
|
var mavenRef;
|
||||||
|
// It's already in gradle form if it has two ':'s
|
||||||
|
if (/:.*:/.exec(p)) {
|
||||||
|
mavenRef = p;
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < SYSTEM_LIBRARY_MAPPINGS.length; ++i) {
|
||||||
|
var pair = SYSTEM_LIBRARY_MAPPINGS[i];
|
||||||
|
if (pair[0].exec(p)) {
|
||||||
|
mavenRef = p.replace(pair[0], pair[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mavenRef) {
|
||||||
|
throw new CordovaError('Unsupported system library (does not work with gradle): ' + p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
depsList += ' compile "' + mavenRef + '"\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
||||||
|
var includeList = '';
|
||||||
|
|
||||||
|
propertiesObj.gradleIncludes.forEach(function (includePath) {
|
||||||
|
includeList += 'apply from: "../' + includePath + '"\n';
|
||||||
|
});
|
||||||
|
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + includeList + '$2');
|
||||||
|
// This needs to be stored in the app gradle, not the root grade
|
||||||
|
fs.writeFileSync(path.join(this.root, 'app', 'build.gradle'), buildGradle);
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioBuilder.prototype.prepEnv = function (opts) {
|
||||||
|
var self = this;
|
||||||
|
return check_reqs.check_gradle()
|
||||||
|
.then(function (gradlePath) {
|
||||||
|
return self.runGradleWrapper(gradlePath);
|
||||||
|
}).then(function () {
|
||||||
|
return self.prepBuildFiles();
|
||||||
|
}).then(function () {
|
||||||
|
// If the gradle distribution URL is set, make sure it points to version we want.
|
||||||
|
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
||||||
|
// For some reason, using ^ and $ don't work. This does the job, though.
|
||||||
|
var distributionUrlRegex = /distributionUrl.*zip/;
|
||||||
|
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
|
||||||
|
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
||||||
|
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
||||||
|
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
|
||||||
|
|
||||||
|
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
||||||
|
var propertiesFilePath = path.join(self.root, propertiesFile);
|
||||||
|
if (opts.packageInfo) {
|
||||||
|
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
||||||
|
} else if (isAutoGenerated(propertiesFilePath)) {
|
||||||
|
shell.rm('-f', propertiesFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Builds the project with gradle.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
StudioBuilder.prototype.build = function (opts) {
|
||||||
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
|
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
||||||
|
|
||||||
|
return spawn(wrapper, args, {stdio: 'pipe'})
|
||||||
|
.progress(function (stdio) {
|
||||||
|
if (stdio.stderr) {
|
||||||
|
/*
|
||||||
|
* Workaround for the issue with Java printing some unwanted information to
|
||||||
|
* stderr instead of stdout.
|
||||||
|
* This function suppresses 'Picked up _JAVA_OPTIONS' message from being
|
||||||
|
* printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
|
||||||
|
* explanation.
|
||||||
|
*/
|
||||||
|
var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
|
||||||
|
if (suppressThisLine) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
process.stderr.write(stdio.stderr);
|
||||||
|
} else {
|
||||||
|
process.stdout.write(stdio.stdout);
|
||||||
|
}
|
||||||
|
}).catch(function (error) {
|
||||||
|
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
||||||
|
return check_reqs.check_android_target(error).then(function () {
|
||||||
|
// If due to some odd reason - check_android_target succeeds
|
||||||
|
// we should still fail here.
|
||||||
|
return Q.reject(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Q.reject(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioBuilder.prototype.clean = function (opts) {
|
||||||
|
var builder = this;
|
||||||
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
|
var args = builder.getArgs('clean', opts);
|
||||||
|
return Q().then(function () {
|
||||||
|
return spawn(wrapper, args, {stdio: 'inherit'});
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
shell.rm('-rf', path.join(builder.root, 'out'));
|
||||||
|
|
||||||
|
['debug', 'release'].forEach(function (config) {
|
||||||
|
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
||||||
|
if (isAutoGenerated(propertiesFilePath)) {
|
||||||
|
shell.rm('-f', propertiesFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = StudioBuilder;
|
||||||
|
|
||||||
|
function isAutoGenerated (file) {
|
||||||
|
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
|
||||||
|
}
|
46
bin/templates/cordova/lib/builders/builders.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
|
var knownBuilders = {
|
||||||
|
gradle: 'GradleBuilder',
|
||||||
|
studio: 'StudioBuilder',
|
||||||
|
none: 'GenericBuilder'
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that instantiates and returns a builder for specified build
|
||||||
|
* type.
|
||||||
|
*
|
||||||
|
* @param {String} builderType Builder name to construct and return. Must
|
||||||
|
* be one of 'ant', 'gradle' or 'none'
|
||||||
|
*
|
||||||
|
* @return {Builder} A builder instance for specified build type.
|
||||||
|
*/
|
||||||
|
module.exports.getBuilder = function (builderType, projectRoot) {
|
||||||
|
if (!knownBuilders[builderType]) { throw new CordovaError('Builder ' + builderType + ' is not supported.'); }
|
||||||
|
|
||||||
|
try {
|
||||||
|
var Builder = require('./' + knownBuilders[builderType]);
|
||||||
|
return new Builder(projectRoot);
|
||||||
|
} catch (err) {
|
||||||
|
throw new CordovaError('Failed to instantiate ' + knownBuilders[builderType] + ' builder: ' + err);
|
||||||
|
}
|
||||||
|
};
|
432
bin/templates/cordova/lib/check_reqs.js
vendored
Normal file
@ -0,0 +1,432 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* jshint sub:true */
|
||||||
|
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
var child_process = require('child_process');
|
||||||
|
var Q = require('q');
|
||||||
|
var path = require('path');
|
||||||
|
var fs = require('fs');
|
||||||
|
var os = require('os');
|
||||||
|
var REPO_ROOT = path.join(__dirname, '..', '..', '..', '..');
|
||||||
|
var PROJECT_ROOT = path.join(__dirname, '..', '..');
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var superspawn = require('cordova-common').superspawn;
|
||||||
|
var android_sdk = require('./android_sdk');
|
||||||
|
|
||||||
|
function forgivingWhichSync (cmd) {
|
||||||
|
try {
|
||||||
|
return fs.realpathSync(shelljs.which(cmd));
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryCommand (cmd, errMsg, catchStderr) {
|
||||||
|
var d = Q.defer();
|
||||||
|
child_process.exec(cmd, function (err, stdout, stderr) {
|
||||||
|
if (err) d.reject(new CordovaError(errMsg));
|
||||||
|
// Sometimes it is necessary to return an stderr instead of stdout in case of success, since
|
||||||
|
// some commands prints theirs output to stderr instead of stdout. 'javac' is the example
|
||||||
|
else d.resolve((catchStderr ? stderr : stdout).trim());
|
||||||
|
});
|
||||||
|
return d.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.isWindows = function () {
|
||||||
|
return (os.platform() === 'win32');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.isDarwin = function () {
|
||||||
|
return (os.platform() === 'darwin');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get valid target from framework/project.properties if run from this repo
|
||||||
|
// Otherwise get target from project.properties file within a generated cordova-android project
|
||||||
|
module.exports.get_target = function () {
|
||||||
|
function extractFromFile (filePath) {
|
||||||
|
var target = shelljs.grep(/\btarget=/, filePath);
|
||||||
|
if (!target) {
|
||||||
|
throw new Error('Could not find android target within: ' + filePath);
|
||||||
|
}
|
||||||
|
return target.split('=')[1].trim();
|
||||||
|
}
|
||||||
|
var repo_file = path.join(REPO_ROOT, 'framework', 'project.properties');
|
||||||
|
if (fs.existsSync(repo_file)) {
|
||||||
|
return extractFromFile(repo_file);
|
||||||
|
}
|
||||||
|
var project_file = path.join(PROJECT_ROOT, 'project.properties');
|
||||||
|
if (fs.existsSync(project_file)) {
|
||||||
|
// if no target found, we're probably in a project and project.properties is in PROJECT_ROOT.
|
||||||
|
return extractFromFile(project_file);
|
||||||
|
}
|
||||||
|
throw new Error('Could not find android target in either ' + repo_file + ' nor ' + project_file);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise. Called only by build and clean commands.
|
||||||
|
module.exports.check_ant = function () {
|
||||||
|
return superspawn.spawn('ant', ['-version']).then(function (output) {
|
||||||
|
// Parse Ant version from command output
|
||||||
|
return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
|
||||||
|
}).catch(function (err) {
|
||||||
|
if (err) {
|
||||||
|
throw new CordovaError('Failed to run `ant -version`. Make sure you have `ant` on your $PATH.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.get_gradle_wrapper = function () {
|
||||||
|
var androidStudioPath;
|
||||||
|
var i = 0;
|
||||||
|
var foundStudio = false;
|
||||||
|
var program_dir;
|
||||||
|
// OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually!
|
||||||
|
if (module.exports.isWindows()) {
|
||||||
|
|
||||||
|
var result = child_process.spawnSync(path.join(__dirname, 'getASPath.bat'));
|
||||||
|
// console.log('result.stdout =' + result.stdout.toString());
|
||||||
|
// console.log('result.stderr =' + result.stderr.toString());
|
||||||
|
|
||||||
|
if (result.stderr.toString().length > 0) {
|
||||||
|
var androidPath = path.join(process.env['ProgramFiles'], 'Android') + '/';
|
||||||
|
if (fs.existsSync(androidPath)) {
|
||||||
|
program_dir = fs.readdirSync(androidPath);
|
||||||
|
while (i < program_dir.length && !foundStudio) {
|
||||||
|
if (program_dir[i].startsWith('Android Studio')) {
|
||||||
|
foundStudio = true;
|
||||||
|
androidStudioPath = path.join(process.env['ProgramFiles'], 'Android', program_dir[i], 'gradle');
|
||||||
|
} else { ++i; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// console.log('got android studio path from registry');
|
||||||
|
// remove the (os independent) new line char at the end of stdout
|
||||||
|
// add gradle to match the above.
|
||||||
|
androidStudioPath = path.join(result.stdout.toString().split('\r\n')[0], 'gradle');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (androidStudioPath !== null && fs.existsSync(androidStudioPath)) {
|
||||||
|
var dirs = fs.readdirSync(androidStudioPath);
|
||||||
|
if (dirs[0].split('-')[0] === 'gradle') {
|
||||||
|
return path.join(androidStudioPath, dirs[0], 'bin', 'gradle');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// OK, let's try to check for Gradle!
|
||||||
|
return forgivingWhichSync('gradle');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise. Called only by build and clean commands.
|
||||||
|
module.exports.check_gradle = function () {
|
||||||
|
var sdkDir = process.env['ANDROID_HOME'];
|
||||||
|
var d = Q.defer();
|
||||||
|
if (!sdkDir) {
|
||||||
|
return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' +
|
||||||
|
'Might need to install Android SDK or set up \'ANDROID_HOME\' env variable.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var gradlePath = module.exports.get_gradle_wrapper();
|
||||||
|
if (gradlePath.length !== 0) { d.resolve(gradlePath); } else {
|
||||||
|
d.reject(new CordovaError('Could not find an installed version of Gradle either in Android Studio,\n' +
|
||||||
|
'or on your system to install the gradle wrapper. Please include gradle \n' +
|
||||||
|
'in your path, or install Android Studio'));
|
||||||
|
}
|
||||||
|
return d.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
module.exports.check_java = function () {
|
||||||
|
var javacPath = forgivingWhichSync('javac');
|
||||||
|
var hasJavaHome = !!process.env['JAVA_HOME'];
|
||||||
|
return Q().then(function () {
|
||||||
|
if (hasJavaHome) {
|
||||||
|
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
|
||||||
|
if (!javacPath) {
|
||||||
|
process.env['PATH'] += path.delimiter + path.join(process.env['JAVA_HOME'], 'bin');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (javacPath) {
|
||||||
|
// OS X has a command for finding JAVA_HOME.
|
||||||
|
var find_java = '/usr/libexec/java_home';
|
||||||
|
var default_java_error_msg = 'Failed to find \'JAVA_HOME\' environment variable. Try setting it manually.';
|
||||||
|
if (fs.existsSync(find_java)) {
|
||||||
|
return superspawn.spawn(find_java).then(function (stdout) {
|
||||||
|
process.env['JAVA_HOME'] = stdout.trim();
|
||||||
|
}).catch(function (err) {
|
||||||
|
if (err) {
|
||||||
|
throw new CordovaError(default_java_error_msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// See if we can derive it from javac's location.
|
||||||
|
// fs.realpathSync is require on Ubuntu, which symplinks from /usr/bin -> JDK
|
||||||
|
var maybeJavaHome = path.dirname(path.dirname(javacPath));
|
||||||
|
if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {
|
||||||
|
process.env['JAVA_HOME'] = maybeJavaHome;
|
||||||
|
} else {
|
||||||
|
throw new CordovaError(default_java_error_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (module.exports.isWindows()) {
|
||||||
|
// Try to auto-detect java in the default install paths.
|
||||||
|
var oldSilent = shelljs.config.silent;
|
||||||
|
shelljs.config.silent = true;
|
||||||
|
var firstJdkDir =
|
||||||
|
shelljs.ls(process.env['ProgramFiles'] + '\\java\\jdk*')[0] ||
|
||||||
|
shelljs.ls('C:\\Program Files\\java\\jdk*')[0] ||
|
||||||
|
shelljs.ls('C:\\Program Files (x86)\\java\\jdk*')[0];
|
||||||
|
shelljs.config.silent = oldSilent;
|
||||||
|
if (firstJdkDir) {
|
||||||
|
// shelljs always uses / in paths.
|
||||||
|
firstJdkDir = firstJdkDir.replace(/\//g, path.sep);
|
||||||
|
if (!javacPath) {
|
||||||
|
process.env['PATH'] += path.delimiter + path.join(firstJdkDir, 'bin');
|
||||||
|
}
|
||||||
|
process.env['JAVA_HOME'] = firstJdkDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(function () {
|
||||||
|
var msg =
|
||||||
|
'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
|
||||||
|
'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
|
||||||
|
if (process.env['JAVA_HOME']) {
|
||||||
|
msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
|
||||||
|
}
|
||||||
|
// We use tryCommand with catchStderr = true, because
|
||||||
|
// javac writes version info to stderr instead of stdout
|
||||||
|
return tryCommand('javac -version', msg, true).then(function (output) {
|
||||||
|
// Let's check for at least Java 8, and keep it future proof so we can support Java 10
|
||||||
|
var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output);
|
||||||
|
return match && match[1];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
module.exports.check_android = function () {
|
||||||
|
return Q().then(function () {
|
||||||
|
var androidCmdPath = forgivingWhichSync('android');
|
||||||
|
var adbInPath = forgivingWhichSync('adb');
|
||||||
|
var avdmanagerInPath = forgivingWhichSync('avdmanager');
|
||||||
|
var hasAndroidHome = !!process.env['ANDROID_HOME'] && fs.existsSync(process.env['ANDROID_HOME']);
|
||||||
|
function maybeSetAndroidHome (value) {
|
||||||
|
if (!hasAndroidHome && fs.existsSync(value)) {
|
||||||
|
hasAndroidHome = true;
|
||||||
|
process.env['ANDROID_HOME'] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// First ensure ANDROID_HOME is set
|
||||||
|
// If we have no hints (nothing in PATH), try a few default locations
|
||||||
|
if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath) {
|
||||||
|
if (module.exports.isWindows()) {
|
||||||
|
// Android Studio 1.0 installer
|
||||||
|
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'sdk'));
|
||||||
|
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'sdk'));
|
||||||
|
// Android Studio pre-1.0 installer
|
||||||
|
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-studio', 'sdk'));
|
||||||
|
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-studio', 'sdk'));
|
||||||
|
// Stand-alone installer
|
||||||
|
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-sdk'));
|
||||||
|
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-sdk'));
|
||||||
|
} else if (module.exports.isDarwin()) {
|
||||||
|
// Android Studio 1.0 installer
|
||||||
|
maybeSetAndroidHome(path.join(process.env['HOME'], 'Library', 'Android', 'sdk'));
|
||||||
|
// Android Studio pre-1.0 installer
|
||||||
|
maybeSetAndroidHome('/Applications/Android Studio.app/sdk');
|
||||||
|
// Stand-alone zip file that user might think to put under /Applications
|
||||||
|
maybeSetAndroidHome('/Applications/android-sdk-macosx');
|
||||||
|
maybeSetAndroidHome('/Applications/android-sdk');
|
||||||
|
}
|
||||||
|
if (process.env['HOME']) {
|
||||||
|
// Stand-alone zip file that user might think to put under their home directory
|
||||||
|
maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk-macosx'));
|
||||||
|
maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasAndroidHome) {
|
||||||
|
// If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to infer from the tooling PATH.
|
||||||
|
var parentDir, grandParentDir;
|
||||||
|
if (androidCmdPath) {
|
||||||
|
parentDir = path.dirname(androidCmdPath);
|
||||||
|
grandParentDir = path.dirname(parentDir);
|
||||||
|
if (path.basename(parentDir) === 'tools' || fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
|
||||||
|
maybeSetAndroidHome(grandParentDir);
|
||||||
|
} else {
|
||||||
|
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
||||||
|
'Detected \'android\' command at ' + parentDir + ' but no \'tools\' directory found near.\n' +
|
||||||
|
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools directory.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (adbInPath) {
|
||||||
|
parentDir = path.dirname(adbInPath);
|
||||||
|
grandParentDir = path.dirname(parentDir);
|
||||||
|
if (path.basename(parentDir) === 'platform-tools') {
|
||||||
|
maybeSetAndroidHome(grandParentDir);
|
||||||
|
} else {
|
||||||
|
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
||||||
|
'Detected \'adb\' command at ' + parentDir + ' but no \'platform-tools\' directory found near.\n' +
|
||||||
|
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'platform-tools directory.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (avdmanagerInPath) {
|
||||||
|
parentDir = path.dirname(avdmanagerInPath);
|
||||||
|
grandParentDir = path.dirname(parentDir);
|
||||||
|
if (path.basename(parentDir) === 'bin' && path.basename(grandParentDir) === 'tools') {
|
||||||
|
maybeSetAndroidHome(path.dirname(grandParentDir));
|
||||||
|
} else {
|
||||||
|
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
||||||
|
'Detected \'avdmanager\' command at ' + parentDir + ' but no \'tools' + path.sep + 'bin\' directory found near.\n' +
|
||||||
|
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools' + path.sep + 'bin directory.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!process.env['ANDROID_HOME']) {
|
||||||
|
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
||||||
|
'Failed to find \'android\' command in your \'PATH\'. Try update your \'PATH\' to include path to valid SDK directory.');
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(process.env['ANDROID_HOME'])) {
|
||||||
|
throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent path: ' + process.env['ANDROID_HOME'] +
|
||||||
|
'\nTry update it manually to point to valid SDK directory.');
|
||||||
|
}
|
||||||
|
// Next let's make sure relevant parts of the SDK tooling is in our PATH
|
||||||
|
if (hasAndroidHome && !androidCmdPath) {
|
||||||
|
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools');
|
||||||
|
}
|
||||||
|
if (hasAndroidHome && !adbInPath) {
|
||||||
|
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'platform-tools');
|
||||||
|
}
|
||||||
|
if (hasAndroidHome && !avdmanagerInPath) {
|
||||||
|
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools', 'bin');
|
||||||
|
}
|
||||||
|
return hasAndroidHome;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: is this actually needed?
|
||||||
|
module.exports.getAbsoluteAndroidCmd = function () {
|
||||||
|
var cmd = forgivingWhichSync('android');
|
||||||
|
if (cmd.length === 0) {
|
||||||
|
cmd = forgivingWhichSync('sdkmanager');
|
||||||
|
}
|
||||||
|
if (module.exports.isWindows()) {
|
||||||
|
return '"' + cmd + '"';
|
||||||
|
}
|
||||||
|
return cmd.replace(/(\s)/g, '\\$1');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.check_android_target = function (originalError) {
|
||||||
|
// valid_target can look like:
|
||||||
|
// android-19
|
||||||
|
// android-L
|
||||||
|
// Google Inc.:Google APIs:20
|
||||||
|
// Google Inc.:Glass Development Kit Preview:20
|
||||||
|
var desired_api_level = module.exports.get_target();
|
||||||
|
return android_sdk.list_targets().then(function (targets) {
|
||||||
|
if (targets.indexOf(desired_api_level) >= 0) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
var androidCmd = module.exports.getAbsoluteAndroidCmd();
|
||||||
|
var msg = 'Please install Android target / API level: "' + desired_api_level + '".\n\n' +
|
||||||
|
'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
|
||||||
|
'You will require:\n' +
|
||||||
|
'1. "SDK Platform" for API level ' + desired_api_level + '\n' +
|
||||||
|
'2. "Android SDK Platform-tools (latest)\n' +
|
||||||
|
'3. "Android SDK Build-tools" (latest)';
|
||||||
|
if (originalError) {
|
||||||
|
msg = originalError + '\n' + msg;
|
||||||
|
}
|
||||||
|
throw new CordovaError(msg);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
module.exports.run = function () {
|
||||||
|
return Q.all([this.check_java(), this.check_android()]).then(function (values) {
|
||||||
|
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
|
||||||
|
console.log('JAVA_HOME=' + process.env['JAVA_HOME']);
|
||||||
|
|
||||||
|
if (!values[0]) {
|
||||||
|
throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!values[1]) {
|
||||||
|
throw new CordovaError('Requirements check failed for Android SDK');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object thar represents one of requirements for current platform.
|
||||||
|
* @param {String} id The unique identifier for this requirements.
|
||||||
|
* @param {String} name The name of requirements. Human-readable field.
|
||||||
|
* @param {String} version The version of requirement installed. In some cases could be an array of strings
|
||||||
|
* (for example, check_android_target returns an array of android targets installed)
|
||||||
|
* @param {Boolean} installed Indicates whether the requirement is installed or not
|
||||||
|
*/
|
||||||
|
var Requirement = function (id, name, version, installed) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.installed = installed || false;
|
||||||
|
this.metadata = {
|
||||||
|
version: version
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methods that runs all checks one by one and returns a result of checks
|
||||||
|
* as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs method
|
||||||
|
*
|
||||||
|
* @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
|
||||||
|
*/
|
||||||
|
module.exports.check_all = function () {
|
||||||
|
|
||||||
|
var requirements = [
|
||||||
|
new Requirement('java', 'Java JDK'),
|
||||||
|
new Requirement('androidSdk', 'Android SDK'),
|
||||||
|
new Requirement('androidTarget', 'Android target'),
|
||||||
|
new Requirement('gradle', 'Gradle')
|
||||||
|
];
|
||||||
|
|
||||||
|
var checkFns = [
|
||||||
|
this.check_java,
|
||||||
|
this.check_android,
|
||||||
|
this.check_android_target,
|
||||||
|
this.check_gradle
|
||||||
|
];
|
||||||
|
|
||||||
|
// Then execute requirement checks one-by-one
|
||||||
|
return checkFns.reduce(function (promise, checkFn, idx) {
|
||||||
|
// Update each requirement with results
|
||||||
|
var requirement = requirements[idx];
|
||||||
|
return promise.then(checkFn).then(function (version) {
|
||||||
|
requirement.installed = true;
|
||||||
|
requirement.metadata.version = version;
|
||||||
|
}, function (err) {
|
||||||
|
requirement.metadata.reason = err instanceof Error ? err.message : err;
|
||||||
|
});
|
||||||
|
}, Q()).then(function () {
|
||||||
|
// When chain is completed, return requirements array to upstream API
|
||||||
|
return requirements;
|
||||||
|
});
|
||||||
|
};
|
112
bin/templates/cordova/lib/device.js
vendored
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var build = require('./build');
|
||||||
|
var path = require('path');
|
||||||
|
var Adb = require('./Adb');
|
||||||
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
|
var spawn = require('cordova-common').superspawn.spawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise for the list of the device ID's found
|
||||||
|
* @param lookHarder When true, try restarting adb if no devices are found.
|
||||||
|
*/
|
||||||
|
module.exports.list = function (lookHarder) {
|
||||||
|
return Adb.devices().then(function (list) {
|
||||||
|
if (list.length === 0 && lookHarder) {
|
||||||
|
// adb kill-server doesn't seem to do the trick.
|
||||||
|
// Could probably find a x-platform version of killall, but I'm not actually
|
||||||
|
// sure that this scenario even happens on non-OSX machines.
|
||||||
|
return spawn('killall', ['adb']).then(function () {
|
||||||
|
events.emit('verbose', 'Restarting adb to see if more devices are detected.');
|
||||||
|
return Adb.devices();
|
||||||
|
}, function () {
|
||||||
|
// For non-killall OS's.
|
||||||
|
return list;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.resolveTarget = function (target) {
|
||||||
|
return this.list(true).then(function (device_list) {
|
||||||
|
if (!device_list || !device_list.length) {
|
||||||
|
return Q.reject(new CordovaError('Failed to deploy to device, no devices found.'));
|
||||||
|
}
|
||||||
|
// default device
|
||||||
|
target = target || device_list[0];
|
||||||
|
|
||||||
|
if (device_list.indexOf(target) < 0) {
|
||||||
|
return Q.reject('ERROR: Unable to find target \'' + target + '\'.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return build.detectArchitecture(target).then(function (arch) {
|
||||||
|
return { target: target, arch: arch, isEmulator: false };
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Installs a previously built application on the device
|
||||||
|
* and launches it.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.install = function (target, buildResults) {
|
||||||
|
return Q().then(function () {
|
||||||
|
if (target && typeof target === 'object') {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
return module.exports.resolveTarget(target);
|
||||||
|
}).then(function (resolvedTarget) {
|
||||||
|
var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
|
||||||
|
var manifest = new AndroidManifest(path.join(__dirname, '../../app/src/main/AndroidManifest.xml'));
|
||||||
|
var pkgName = manifest.getPackageId();
|
||||||
|
var launchName = pkgName + '/.' + manifest.getActivity().getName();
|
||||||
|
events.emit('log', 'Using apk: ' + apk_path);
|
||||||
|
events.emit('log', 'Package name: ' + pkgName);
|
||||||
|
|
||||||
|
return Adb.install(resolvedTarget.target, apk_path, {replace: true}).catch(function (error) {
|
||||||
|
// CB-9557 CB-10157 only uninstall and reinstall app if the one that
|
||||||
|
// is already installed on device was signed w/different certificate
|
||||||
|
if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString())) { throw error; }
|
||||||
|
|
||||||
|
events.emit('warn', 'Uninstalling app from device and reinstalling it again because the ' +
|
||||||
|
'installed app already signed with different key');
|
||||||
|
|
||||||
|
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
||||||
|
// or the app doesn't installed at all, so no error catching needed.
|
||||||
|
return Adb.uninstall(resolvedTarget.target, pkgName).then(function () {
|
||||||
|
return Adb.install(resolvedTarget.target, apk_path, {replace: true});
|
||||||
|
});
|
||||||
|
}).then(function () {
|
||||||
|
// unlock screen
|
||||||
|
return Adb.shell(resolvedTarget.target, 'input keyevent 82');
|
||||||
|
}).then(function () {
|
||||||
|
return Adb.start(resolvedTarget.target, launchName);
|
||||||
|
}).then(function () {
|
||||||
|
events.emit('log', 'LAUNCH SUCCESS');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
531
bin/templates/cordova/lib/emulator.js
vendored
Normal file
@ -0,0 +1,531 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* jshint sub:true */
|
||||||
|
|
||||||
|
var android_versions = require('android-versions');
|
||||||
|
var retry = require('./retry');
|
||||||
|
var build = require('./build');
|
||||||
|
var path = require('path');
|
||||||
|
var Adb = require('./Adb');
|
||||||
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
var superspawn = require('cordova-common').superspawn;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
var android_sdk = require('./android_sdk');
|
||||||
|
var check_reqs = require('./check_reqs');
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var os = require('os');
|
||||||
|
var fs = require('fs');
|
||||||
|
var child_process = require('child_process');
|
||||||
|
|
||||||
|
// constants
|
||||||
|
var ONE_SECOND = 1000; // in milliseconds
|
||||||
|
var ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
|
||||||
|
var INSTALL_COMMAND_TIMEOUT = 5 * ONE_MINUTE; // in milliseconds
|
||||||
|
var NUM_INSTALL_RETRIES = 3;
|
||||||
|
var CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds
|
||||||
|
var EXEC_KILL_SIGNAL = 'SIGKILL';
|
||||||
|
|
||||||
|
function forgivingWhichSync (cmd) {
|
||||||
|
try {
|
||||||
|
return fs.realpathSync(shelljs.which(cmd));
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.list_images_using_avdmanager = function () {
|
||||||
|
return superspawn.spawn('avdmanager', ['list', 'avd']).then(function (output) {
|
||||||
|
var response = output.split('\n');
|
||||||
|
var emulator_list = [];
|
||||||
|
for (var i = 1; i < response.length; i++) {
|
||||||
|
// To return more detailed information use img_obj
|
||||||
|
var img_obj = {};
|
||||||
|
if (response[i].match(/Name:\s/)) {
|
||||||
|
img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
|
||||||
|
if (response[i + 1].match(/Device:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/Path:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/Target:\s/)) {
|
||||||
|
i++;
|
||||||
|
if (response[i + 1].match(/ABI:\s/)) {
|
||||||
|
img_obj['abi'] = response[i + 1].split('ABI: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
// This next conditional just aims to match the old output of `android list avd`
|
||||||
|
// We do so so that we don't have to change the logic when parsing for the
|
||||||
|
// best emulator target to spawn (see below in `best_image`)
|
||||||
|
// This allows us to transitionally support both `android` and `avdmanager` binaries,
|
||||||
|
// depending on what SDK version the user has
|
||||||
|
if (response[i + 1].match(/Based\son:\s/)) {
|
||||||
|
img_obj['target'] = response[i + 1].split('Based on:')[1];
|
||||||
|
if (img_obj['target'].match(/Tag\/ABI:\s/)) {
|
||||||
|
img_obj['target'] = img_obj['target'].split('Tag/ABI:')[0].replace('\r', '').trim();
|
||||||
|
if (img_obj['target'].indexOf('(') > -1) {
|
||||||
|
img_obj['target'] = img_obj['target'].substr(0, img_obj['target'].indexOf('(') - 1).trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var version_string = img_obj['target'].replace(/Android\s+/, '');
|
||||||
|
|
||||||
|
var api_level = android_sdk.version_string_to_api_level[version_string];
|
||||||
|
if (api_level) {
|
||||||
|
img_obj['target'] += ' (API level ' + api_level + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/Skin:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
emulator_list.push(img_obj);
|
||||||
|
}
|
||||||
|
/* To just return a list of names use this
|
||||||
|
if (response[i].match(/Name:\s/)) {
|
||||||
|
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
||||||
|
} */
|
||||||
|
|
||||||
|
}
|
||||||
|
return emulator_list;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.list_images_using_android = function () {
|
||||||
|
return superspawn.spawn('android', ['list', 'avd']).then(function (output) {
|
||||||
|
var response = output.split('\n');
|
||||||
|
var emulator_list = [];
|
||||||
|
for (var i = 1; i < response.length; i++) {
|
||||||
|
// To return more detailed information use img_obj
|
||||||
|
var img_obj = {};
|
||||||
|
if (response[i].match(/Name:\s/)) {
|
||||||
|
img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
|
||||||
|
if (response[i + 1].match(/Device:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/Path:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/\(API\slevel\s/) || (response[i + 2] && response[i + 2].match(/\(API\slevel\s/))) {
|
||||||
|
i++;
|
||||||
|
var secondLine = response[i + 1].match(/\(API\slevel\s/) ? response[i + 1] : '';
|
||||||
|
img_obj['target'] = (response[i] + secondLine).split('Target: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/ABI:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['abi'] = response[i].split('ABI: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
if (response[i + 1].match(/Skin:\s/)) {
|
||||||
|
i++;
|
||||||
|
img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
emulator_list.push(img_obj);
|
||||||
|
}
|
||||||
|
/* To just return a list of names use this
|
||||||
|
if (response[i].match(/Name:\s/)) {
|
||||||
|
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
||||||
|
} */
|
||||||
|
|
||||||
|
}
|
||||||
|
return emulator_list;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Promise for a list of emulator images in the form of objects
|
||||||
|
* {
|
||||||
|
name : <emulator_name>,
|
||||||
|
device : <device>,
|
||||||
|
path : <path_to_emulator_image>,
|
||||||
|
target : <api_target>,
|
||||||
|
abi : <cpu>,
|
||||||
|
skin : <skin>
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
module.exports.list_images = function () {
|
||||||
|
return Q.fcall(function () {
|
||||||
|
if (forgivingWhichSync('avdmanager')) {
|
||||||
|
return module.exports.list_images_using_avdmanager();
|
||||||
|
} else if (forgivingWhichSync('android')) {
|
||||||
|
return module.exports.list_images_using_android();
|
||||||
|
} else {
|
||||||
|
return Q().then(function () {
|
||||||
|
throw new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).then(function (avds) {
|
||||||
|
// In case we're missing the Android OS version string from the target description, add it.
|
||||||
|
return avds.map(function (avd) {
|
||||||
|
if (avd.target && avd.target.indexOf('Android API') > -1 && avd.target.indexOf('API level') < 0) {
|
||||||
|
var api_level = avd.target.match(/\d+/);
|
||||||
|
if (api_level) {
|
||||||
|
var level = android_versions.get(api_level);
|
||||||
|
avd.target = 'Android ' + level.semver + ' (API level ' + api_level + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return avd;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will return the closest avd to the projects target
|
||||||
|
* or undefined if no avds exist.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.best_image = function () {
|
||||||
|
return this.list_images().then(function (images) {
|
||||||
|
// Just return undefined if there is no images
|
||||||
|
if (images.length === 0) return;
|
||||||
|
|
||||||
|
var closest = 9999;
|
||||||
|
var best = images[0];
|
||||||
|
var project_target = parseInt(check_reqs.get_target().replace('android-', ''));
|
||||||
|
for (var i in images) {
|
||||||
|
var target = images[i].target;
|
||||||
|
if (target && target.indexOf('API level') > -1) {
|
||||||
|
var num = parseInt(target.split('(API level ')[1].replace(')', ''));
|
||||||
|
if (num === project_target) {
|
||||||
|
return images[i];
|
||||||
|
} else if (project_target - num < closest && project_target > num) {
|
||||||
|
closest = project_target - num;
|
||||||
|
best = images[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
module.exports.list_started = function () {
|
||||||
|
return Adb.devices({emulators: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a promise.
|
||||||
|
// TODO: we should remove this, there's a more robust method under android_sdk.js
|
||||||
|
module.exports.list_targets = function () {
|
||||||
|
return superspawn.spawn('android', ['list', 'targets'], {cwd: os.tmpdir()}).then(function (output) {
|
||||||
|
var target_out = output.split('\n');
|
||||||
|
var targets = [];
|
||||||
|
for (var i = target_out.length; i >= 0; i--) {
|
||||||
|
if (target_out[i].match(/id:/)) {
|
||||||
|
targets.push(targets[i].split(' ')[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets unused port for android emulator, between 5554 and 5584
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.get_available_port = function () {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return self.list_started().then(function (emulators) {
|
||||||
|
for (var p = 5584; p >= 5554; p -= 2) {
|
||||||
|
if (emulators.indexOf('emulator-' + p) === -1) {
|
||||||
|
events.emit('verbose', 'Found available port: ' + p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new CordovaError('Could not find an available avd port');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Starts an emulator with the given ID,
|
||||||
|
* and returns the started ID of that emulator.
|
||||||
|
* If no ID is given it will use the first image available,
|
||||||
|
* if no image is available it will error out (maybe create one?).
|
||||||
|
* If no boot timeout is given or the value is negative it will wait forever for
|
||||||
|
* the emulator to boot
|
||||||
|
*
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.start = function (emulator_ID, boot_timeout) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return Q().then(function () {
|
||||||
|
if (emulator_ID) return Q(emulator_ID);
|
||||||
|
|
||||||
|
return self.best_image().then(function (best) {
|
||||||
|
if (best && best.name) {
|
||||||
|
events.emit('warn', 'No emulator specified, defaulting to ' + best.name);
|
||||||
|
return best.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var androidCmd = check_reqs.getAbsoluteAndroidCmd();
|
||||||
|
return Q.reject(new CordovaError('No emulator images (avds) found.\n' +
|
||||||
|
'1. Download desired System Image by running: ' + androidCmd + ' sdk\n' +
|
||||||
|
'2. Create an AVD by running: ' + androidCmd + ' avd\n' +
|
||||||
|
'HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver\n'));
|
||||||
|
});
|
||||||
|
}).then(function (emulatorId) {
|
||||||
|
return self.get_available_port().then(function (port) {
|
||||||
|
// Figure out the directory the emulator binary runs in, and set the cwd to that directory.
|
||||||
|
// Workaround for https://code.google.com/p/android/issues/detail?id=235461
|
||||||
|
var emulator_dir = path.dirname(shelljs.which('emulator'));
|
||||||
|
var args = ['-avd', emulatorId, '-port', port];
|
||||||
|
// Don't wait for it to finish, since the emulator will probably keep running for a long time.
|
||||||
|
child_process
|
||||||
|
.spawn('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
|
||||||
|
.unref();
|
||||||
|
|
||||||
|
// wait for emulator to start
|
||||||
|
events.emit('log', 'Waiting for emulator to start...');
|
||||||
|
return self.wait_for_emulator(port);
|
||||||
|
});
|
||||||
|
}).then(function (emulatorId) {
|
||||||
|
if (!emulatorId) { return Q.reject(new CordovaError('Failed to start emulator')); }
|
||||||
|
|
||||||
|
// wait for emulator to boot up
|
||||||
|
process.stdout.write('Waiting for emulator to boot (this may take a while)...');
|
||||||
|
return self.wait_for_boot(emulatorId, boot_timeout).then(function (success) {
|
||||||
|
if (success) {
|
||||||
|
events.emit('log', 'BOOT COMPLETE');
|
||||||
|
// unlock screen
|
||||||
|
return Adb.shell(emulatorId, 'input keyevent 82').then(function () {
|
||||||
|
// return the new emulator id for the started emulators
|
||||||
|
return emulatorId;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// We timed out waiting for the boot to happen
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Waits for an emulator to boot on a given port.
|
||||||
|
* Returns this emulator's ID in a promise.
|
||||||
|
*/
|
||||||
|
module.exports.wait_for_emulator = function (port) {
|
||||||
|
var self = this;
|
||||||
|
return Q().then(function () {
|
||||||
|
var emulator_id = 'emulator-' + port;
|
||||||
|
return Adb.shell(emulator_id, 'getprop dev.bootcomplete').then(function (output) {
|
||||||
|
if (output.indexOf('1') >= 0) {
|
||||||
|
return emulator_id;
|
||||||
|
}
|
||||||
|
return self.wait_for_emulator(port);
|
||||||
|
}, function (error) {
|
||||||
|
if ((error && error.message &&
|
||||||
|
(error.message.indexOf('not found') > -1)) ||
|
||||||
|
(error.message.indexOf('device offline') > -1)) {
|
||||||
|
// emulator not yet started, continue waiting
|
||||||
|
return self.wait_for_emulator(port);
|
||||||
|
} else {
|
||||||
|
// something unexpected has happened
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Waits for the core android process of the emulator to start. Returns a
|
||||||
|
* promise that resolves to a boolean indicating success. Not specifying a
|
||||||
|
* time_remaining or passing a negative value will cause it to wait forever
|
||||||
|
*/
|
||||||
|
module.exports.wait_for_boot = function (emulator_id, time_remaining) {
|
||||||
|
var self = this;
|
||||||
|
return Adb.shell(emulator_id, 'ps').then(function (output) {
|
||||||
|
if (output.match(/android\.process\.acore/)) {
|
||||||
|
return true;
|
||||||
|
} else if (time_remaining === 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
process.stdout.write('.');
|
||||||
|
|
||||||
|
// Check at regular intervals
|
||||||
|
return Q.delay(time_remaining < CHECK_BOOTED_INTERVAL ? time_remaining : CHECK_BOOTED_INTERVAL).then(function () {
|
||||||
|
var updated_time = time_remaining >= 0 ? Math.max(time_remaining - CHECK_BOOTED_INTERVAL, 0) : time_remaining;
|
||||||
|
return self.wait_for_boot(emulator_id, updated_time);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create avd
|
||||||
|
* TODO : Enter the stdin input required to complete the creation of an avd.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.create_image = function (name, target) {
|
||||||
|
console.log('Creating new avd named ' + name);
|
||||||
|
if (target) {
|
||||||
|
return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', target]).then(null, function (error) {
|
||||||
|
console.error('ERROR : Failed to create emulator image : ');
|
||||||
|
console.error(' Do you have the latest android targets including ' + target + '?');
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.');
|
||||||
|
// TODO: there's a more robust method for finding targets in android_sdk.js
|
||||||
|
return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', this.list_targets()[0]]).then(function () {
|
||||||
|
// TODO: This seems like another error case, even though it always happens.
|
||||||
|
console.error('ERROR : Unable to create an avd emulator, no targets found.');
|
||||||
|
console.error('Ensure you have targets available by running the "android" command');
|
||||||
|
return Q.reject();
|
||||||
|
}, function (error) {
|
||||||
|
console.error('ERROR : Failed to create emulator image : ');
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.resolveTarget = function (target) {
|
||||||
|
return this.list_started().then(function (emulator_list) {
|
||||||
|
if (emulator_list.length < 1) {
|
||||||
|
return Q.reject('No running Android emulators found, please start an emulator before deploying your project.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// default emulator
|
||||||
|
target = target || emulator_list[0];
|
||||||
|
if (emulator_list.indexOf(target) < 0) {
|
||||||
|
return Q.reject('Unable to find target \'' + target + '\'. Failed to deploy to emulator.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return build.detectArchitecture(target).then(function (arch) {
|
||||||
|
return {target: target, arch: arch, isEmulator: true};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Installs a previously built application on the emulator and launches it.
|
||||||
|
* If no target is specified, then it picks one.
|
||||||
|
* If no started emulators are found, error out.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.install = function (givenTarget, buildResults) {
|
||||||
|
|
||||||
|
var target;
|
||||||
|
// We need to find the proper path to the Android Manifest
|
||||||
|
var manifestPath = path.join(__dirname, '..', '..', 'app', 'src', 'main', 'AndroidManifest.xml');
|
||||||
|
if (buildResults.buildMethod === 'gradle') {
|
||||||
|
manifestPath = path.join(__dirname, '../../AndroidManifest.xml');
|
||||||
|
}
|
||||||
|
var manifest = new AndroidManifest(manifestPath);
|
||||||
|
var pkgName = manifest.getPackageId();
|
||||||
|
|
||||||
|
// resolve the target emulator
|
||||||
|
return Q().then(function () {
|
||||||
|
if (givenTarget && typeof givenTarget === 'object') {
|
||||||
|
return givenTarget;
|
||||||
|
} else {
|
||||||
|
return module.exports.resolveTarget(givenTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the resolved target
|
||||||
|
}).then(function (resolvedTarget) {
|
||||||
|
target = resolvedTarget;
|
||||||
|
|
||||||
|
// install the app
|
||||||
|
}).then(function () {
|
||||||
|
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
||||||
|
// or the app doesn't installed at all, so no error catching needed.
|
||||||
|
return Q.when().then(function () {
|
||||||
|
|
||||||
|
var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
|
||||||
|
var execOptions = {
|
||||||
|
cwd: os.tmpdir(),
|
||||||
|
timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
|
||||||
|
killSignal: EXEC_KILL_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
|
events.emit('log', 'Using apk: ' + apk_path);
|
||||||
|
events.emit('log', 'Package name: ' + pkgName);
|
||||||
|
events.emit('verbose', 'Installing app on emulator...');
|
||||||
|
|
||||||
|
// A special function to call adb install in specific environment w/ specific options.
|
||||||
|
// Introduced as a part of fix for http://issues.apache.org/jira/browse/CB-9119
|
||||||
|
// to workaround sporadic emulator hangs
|
||||||
|
function adbInstallWithOptions (target, apk, opts) {
|
||||||
|
events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');
|
||||||
|
|
||||||
|
var command = 'adb -s ' + target + ' install -r "' + apk + '"';
|
||||||
|
return Q.promise(function (resolve, reject) {
|
||||||
|
child_process.exec(command, opts, function (err, stdout, stderr) {
|
||||||
|
if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
|
||||||
|
// adb does not return an error code even if installation fails. Instead it puts a specific
|
||||||
|
// message to stdout, so we have to use RegExp matching to detect installation failure.
|
||||||
|
else if (/Failure/.test(stdout)) {
|
||||||
|
if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
|
||||||
|
stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
|
||||||
|
' or sign and deploy the unsigned apk manually using Android tools.';
|
||||||
|
} else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
|
||||||
|
stdout += 'You\'re trying to install apk with a lower versionCode that is already installed.' +
|
||||||
|
'\nEither uninstall an app or increment the versionCode.';
|
||||||
|
}
|
||||||
|
|
||||||
|
reject(new CordovaError('Failed to install apk to emulator: ' + stdout));
|
||||||
|
} else resolve(stdout);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function installPromise () {
|
||||||
|
return adbInstallWithOptions(target.target, apk_path, execOptions).catch(function (error) {
|
||||||
|
// CB-9557 CB-10157 only uninstall and reinstall app if the one that
|
||||||
|
// is already installed on device was signed w/different certificate
|
||||||
|
if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString())) { throw error; }
|
||||||
|
|
||||||
|
events.emit('warn', 'Uninstalling app from device and reinstalling it because the ' +
|
||||||
|
'currently installed app was signed with different key');
|
||||||
|
|
||||||
|
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
||||||
|
// or the app doesn't installed at all, so no error catching needed.
|
||||||
|
return Adb.uninstall(target.target, pkgName).then(function () {
|
||||||
|
return adbInstallWithOptions(target.target, apk_path, execOptions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return retry.retryPromise(NUM_INSTALL_RETRIES, installPromise).then(function (output) {
|
||||||
|
events.emit('log', 'INSTALL SUCCESS');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// unlock screen
|
||||||
|
}).then(function () {
|
||||||
|
|
||||||
|
events.emit('verbose', 'Unlocking screen...');
|
||||||
|
return Adb.shell(target.target, 'input keyevent 82');
|
||||||
|
}).then(function () {
|
||||||
|
Adb.start(target.target, pkgName + '/.' + manifest.getActivity().getName());
|
||||||
|
// report success or failure
|
||||||
|
}).then(function (output) {
|
||||||
|
events.emit('log', 'LAUNCH SUCCESS');
|
||||||
|
});
|
||||||
|
};
|
3
bin/templates/cordova/lib/getASPath.bat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Android Studio" /v Path') do set "ASPath=%%~b"
|
||||||
|
ECHO %ASPath%
|
42
bin/templates/cordova/lib/install-device
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var device = require('./device'),
|
||||||
|
args = process.argv;
|
||||||
|
|
||||||
|
if(args.length > 2) {
|
||||||
|
var install_target;
|
||||||
|
if (args[2].substring(0, 9) == '--target=') {
|
||||||
|
install_target = args[2].substring(9, args[2].length);
|
||||||
|
device.install(install_target).done(null, function(err) {
|
||||||
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
device.install().done(null, function(err) {
|
||||||
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
||||||
|
}
|
26
bin/templates/cordova/lib/install-device.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0install-device"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'install-device' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
38
bin/templates/cordova/lib/install-emulator
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var emulator = require('./emulator'),
|
||||||
|
args = process.argv;
|
||||||
|
|
||||||
|
var install_target;
|
||||||
|
if(args.length > 2) {
|
||||||
|
if (args[2].substring(0, 9) == '--target=') {
|
||||||
|
install_target = args[2].substring(9, args[2].length);
|
||||||
|
} else {
|
||||||
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emulator.install(install_target).done(null, function(err) {
|
||||||
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
26
bin/templates/cordova/lib/install-emulator.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0install-emulator"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'install-emulator' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
@ -19,17 +19,15 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { list } = require('cordova-android/lib/target');
|
var devices = require('./device');
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
require('cordova-android/lib/check_reqs').check_android().then(function () {
|
require('./check_reqs').check_android().then(function() {
|
||||||
list().then(targets => {
|
devices.list().done(function(device_list) {
|
||||||
const deviceIds = targets
|
device_list && device_list.forEach(function(dev) {
|
||||||
.filter(({ type }) => type === 'device')
|
console.log(dev);
|
||||||
.map(({ id }) => id);
|
});
|
||||||
|
}, function(err) {
|
||||||
console.log(deviceIds.join('\n'));
|
|
||||||
}, function (err) {
|
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
26
bin/templates/cordova/lib/list-devices.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0list-devices"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'list-devices' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
@ -19,15 +19,15 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const emulators = require('cordova-android/lib/emulator');
|
var emulators = require('./emulator');
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
require('cordova-android/lib/check_reqs').check_android().then(function () {
|
require('./check_reqs').check_android().then(function() {
|
||||||
emulators.list_images().then(function (emulator_list) {
|
emulators.list_images().done(function(emulator_list) {
|
||||||
emulator_list && emulator_list.forEach(function (emu) {
|
emulator_list && emulator_list.forEach(function(emu) {
|
||||||
console.log(emu.name);
|
console.log(emu.name);
|
||||||
});
|
});
|
||||||
}, function (err) {
|
}, function(err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
26
bin/templates/cordova/lib/list-emulator-images.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0list-emulator-images"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'list-emulator-images' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
34
bin/templates/cordova/lib/list-started-emulators
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var emulators = require('./emulator');
|
||||||
|
|
||||||
|
// Usage support for when args are given
|
||||||
|
require('./check_reqs').check_android().then(function() {
|
||||||
|
emulators.list_started().done(function(emulator_list) {
|
||||||
|
emulator_list && emulator_list.forEach(function(emu) {
|
||||||
|
console.log(emu);
|
||||||
|
});
|
||||||
|
}, function(err) {
|
||||||
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
||||||
|
});
|
26
bin/templates/cordova/lib/list-started-emulators.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0list-started-emulators"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'list-started-emulators' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
56
bin/templates/cordova/lib/log.js
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
|
var os = require('os');
|
||||||
|
var Q = require('q');
|
||||||
|
var child_process = require('child_process');
|
||||||
|
var ROOT = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Starts running logcat in the shell.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
module.exports.run = function () {
|
||||||
|
var d = Q.defer();
|
||||||
|
var adb = child_process.spawn('adb', ['logcat'], {cwd: os.tmpdir()});
|
||||||
|
|
||||||
|
adb.stdout.on('data', function (data) {
|
||||||
|
var lines = data ? data.toString().split('\n') : [];
|
||||||
|
var out = lines.filter(function (x) { return x.indexOf('nativeGetEnabledTags') < 0; });
|
||||||
|
console.log(out.join('\n'));
|
||||||
|
});
|
||||||
|
|
||||||
|
adb.stderr.on('data', console.error);
|
||||||
|
adb.on('close', function (code) {
|
||||||
|
if (code > 0) {
|
||||||
|
d.reject('Failed to run logcat command.');
|
||||||
|
} else d.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
return d.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.help = function () {
|
||||||
|
console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
|
||||||
|
console.log('Gives the logcat output on the command line.');
|
||||||
|
process.exit(0);
|
||||||
|
};
|
@ -20,8 +20,10 @@
|
|||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
jcenter()
|
||||||
mavenCentral()
|
maven {
|
||||||
|
url "https://maven.google.com"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch the Android Gradle plugin version requirement depending on the
|
// Switch the Android Gradle plugin version requirement depending on the
|
||||||
@ -36,14 +38,15 @@ buildscript {
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
compile fileTree(dir: 'libs', include: '*.jar')
|
||||||
debugCompile project(path: ":CordovaLib", configuration: "debug")
|
debugCompile project(path: ":CordovaLib", configuration: "debug")
|
||||||
releaseCompile project(path: ":CordovaLib", configuration: "release")
|
releaseCompile project(path: ":CordovaLib", configuration: "release")
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion cordovaConfig.COMPILE_SDK_VERSION
|
compileSdkVersion cdvCompileSdkVersion
|
||||||
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION
|
buildToolsVersion cdvBuildToolsVersion
|
||||||
|
publishNonDefault true
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_6
|
sourceCompatibility JavaVersion.VERSION_1_6
|
@ -14,19 +14,36 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
/* jshint unused: vars */
|
||||||
const path = require('path');
|
|
||||||
const isPathInside = require('is-path-inside');
|
|
||||||
const events = require('cordova-common').events;
|
|
||||||
const CordovaError = require('cordova-common').CordovaError;
|
|
||||||
|
|
||||||
const handlers = {
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
|
var handlers = {
|
||||||
'source-file': {
|
'source-file': {
|
||||||
install: function (obj, plugin, project, options) {
|
install: function (obj, plugin, project, options) {
|
||||||
if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
|
if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
|
||||||
if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
|
if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
|
||||||
|
|
||||||
const dest = getInstallDestination(obj);
|
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||||
|
|
||||||
|
// TODO: This code needs to be replaced, since the core plugins need to be re-mapped to a different location in
|
||||||
|
// a later plugins release. This is for legacy plugins to work with Cordova.
|
||||||
|
|
||||||
|
if (options && options.android_studio === true) {
|
||||||
|
// If a Java file is using the new directory structure, don't penalize it
|
||||||
|
if (!obj.targetDir.includes('app/src/main')) {
|
||||||
|
if (obj.src.endsWith('.java')) {
|
||||||
|
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
||||||
|
} else if (obj.src.endsWith('.xml')) {
|
||||||
|
// We are making a huge assumption here that XML files will be going to res/xml or values/xml
|
||||||
|
dest = path.join('app/src/main', obj.targetDir, path.basename(obj.src));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options && options.force) {
|
if (options && options.force) {
|
||||||
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
||||||
@ -35,48 +52,58 @@ const handlers = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const dest = getInstallDestination(obj);
|
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||||
|
|
||||||
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
|
if (options && options.android_studio === true) {
|
||||||
if (obj.src.endsWith('java')) {
|
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
||||||
deleteJava(project.projectDir, dest);
|
|
||||||
} else {
|
|
||||||
// Just remove the file, not the whole parent directory
|
|
||||||
removeFile(path.resolve(project.projectDir, dest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteJava(project.projectDir, dest);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'lib-file': {
|
'lib-file': {
|
||||||
install: function (obj, plugin, project, options) {
|
install: function (obj, plugin, project, options) {
|
||||||
const dest = path.join('app/libs', path.basename(obj.src));
|
var dest = path.join('libs', path.basename(obj.src));
|
||||||
|
if (options && options.android_studio === true) {
|
||||||
|
dest = path.join('app/libs', path.basename(obj.src));
|
||||||
|
}
|
||||||
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const dest = path.join('app/libs', path.basename(obj.src));
|
var dest = path.join('libs', path.basename(obj.src));
|
||||||
removeFile(path.resolve(project.projectDir, dest));
|
if (options && options.android_studio === true) {
|
||||||
|
dest = path.join('app/libs', path.basename(obj.src));
|
||||||
|
}
|
||||||
|
removeFile(project.projectDir, dest);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'resource-file': {
|
'resource-file': {
|
||||||
install: function (obj, plugin, project, options) {
|
install: function (obj, plugin, project, options) {
|
||||||
const dest = path.join('app', 'src', 'main', obj.target);
|
var dest = path.normalize(obj.target);
|
||||||
|
if (options && options.android_studio === true) {
|
||||||
|
dest = path.join('app/src/main', dest);
|
||||||
|
}
|
||||||
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const dest = path.join('app', 'src', 'main', obj.target);
|
var dest = path.normalize(obj.target);
|
||||||
removeFile(path.resolve(project.projectDir, dest));
|
if (options && options.android_studio === true) {
|
||||||
|
dest = path.join('app/src/main', dest);
|
||||||
|
}
|
||||||
|
removeFile(project.projectDir, dest);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
framework: {
|
'framework': {
|
||||||
install: function (obj, plugin, project, options) {
|
install: function (obj, plugin, project, options) {
|
||||||
const src = obj.src;
|
var src = obj.src;
|
||||||
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
||||||
|
|
||||||
events.emit('verbose', 'Installing Android library: ' + src);
|
events.emit('verbose', 'Installing Android library: ' + src);
|
||||||
const parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
||||||
let subDir;
|
var subDir;
|
||||||
|
|
||||||
if (obj.custom) {
|
if (obj.custom) {
|
||||||
const subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
||||||
copyNewFile(plugin.dir, src, project.projectDir, subRelativeDir, !!(options && options.link));
|
copyNewFile(plugin.dir, src, project.projectDir, subRelativeDir, !!(options && options.link));
|
||||||
subDir = path.resolve(project.projectDir, subRelativeDir);
|
subDir = path.resolve(project.projectDir, subRelativeDir);
|
||||||
} else {
|
} else {
|
||||||
@ -93,19 +120,19 @@ const handlers = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const src = obj.src;
|
var src = obj.src;
|
||||||
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
||||||
|
|
||||||
events.emit('verbose', 'Uninstalling Android library: ' + src);
|
events.emit('verbose', 'Uninstalling Android library: ' + src);
|
||||||
const parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
||||||
let subDir;
|
var subDir;
|
||||||
|
|
||||||
if (obj.custom) {
|
if (obj.custom) {
|
||||||
const subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
||||||
removeFile(path.resolve(project.projectDir, subRelativeDir));
|
removeFile(project.projectDir, subRelativeDir);
|
||||||
subDir = path.resolve(project.projectDir, subRelativeDir);
|
subDir = path.resolve(project.projectDir, subRelativeDir);
|
||||||
// If it's the last framework in the plugin, remove the parent directory.
|
// If it's the last framework in the plugin, remove the parent directory.
|
||||||
const parDir = path.dirname(subDir);
|
var parDir = path.dirname(subDir);
|
||||||
if (fs.existsSync(parDir) && fs.readdirSync(parDir).length === 0) {
|
if (fs.existsSync(parDir) && fs.readdirSync(parDir).length === 0) {
|
||||||
fs.rmdirSync(parDir);
|
fs.rmdirSync(parDir);
|
||||||
}
|
}
|
||||||
@ -139,45 +166,45 @@ const handlers = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const target = obj.target || obj.src;
|
var target = obj.target || obj.src;
|
||||||
|
|
||||||
if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
||||||
|
|
||||||
removeFile(path.resolve(project.www, target));
|
removeFileF(path.resolve(project.www, target));
|
||||||
removeFile(path.resolve(project.www, 'plugins', plugin.id));
|
removeFileF(path.resolve(project.www, 'plugins', plugin.id));
|
||||||
if (options && options.usePlatformWww) {
|
if (options && options.usePlatformWww) {
|
||||||
// CB-11022 remove file from both directories if usePlatformWww is specified
|
// CB-11022 remove file from both directories if usePlatformWww is specified
|
||||||
removeFile(path.resolve(project.platformWww, target));
|
removeFileF(path.resolve(project.platformWww, target));
|
||||||
removeFile(path.resolve(project.platformWww, 'plugins', plugin.id));
|
removeFileF(path.resolve(project.platformWww, 'plugins', plugin.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'js-module': {
|
'js-module': {
|
||||||
install: function (obj, plugin, project, options) {
|
install: function (obj, plugin, project, options) {
|
||||||
// Copy the plugin's files into the www directory.
|
// Copy the plugin's files into the www directory.
|
||||||
const moduleSource = path.resolve(plugin.dir, obj.src);
|
var moduleSource = path.resolve(plugin.dir, obj.src);
|
||||||
const moduleName = plugin.id + '.' + (obj.name || path.basename(obj.src, path.extname(obj.src)));
|
var moduleName = plugin.id + '.' + (obj.name || path.basename(obj.src, path.extname(obj.src)));
|
||||||
|
|
||||||
// Read in the file, prepend the cordova.define, and write it back out.
|
// Read in the file, prepend the cordova.define, and write it back out.
|
||||||
let scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
|
var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
|
||||||
if (moduleSource.match(/.*\.json$/)) {
|
if (moduleSource.match(/.*\.json$/)) {
|
||||||
scriptContent = 'module.exports = ' + scriptContent;
|
scriptContent = 'module.exports = ' + scriptContent;
|
||||||
}
|
}
|
||||||
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
|
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
|
||||||
|
|
||||||
const wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
|
var wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
|
||||||
fs.ensureDirSync(path.dirname(wwwDest));
|
shell.mkdir('-p', path.dirname(wwwDest));
|
||||||
fs.writeFileSync(wwwDest, scriptContent, 'utf-8');
|
fs.writeFileSync(wwwDest, scriptContent, 'utf-8');
|
||||||
|
|
||||||
if (options && options.usePlatformWww) {
|
if (options && options.usePlatformWww) {
|
||||||
// CB-11022 copy file to both directories if usePlatformWww is specified
|
// CB-11022 copy file to both directories if usePlatformWww is specified
|
||||||
const platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
|
var platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
|
||||||
fs.ensureDirSync(path.dirname(platformWwwDest));
|
shell.mkdir('-p', path.dirname(platformWwwDest));
|
||||||
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
|
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
const pluginRelativePath = path.join('plugins', plugin.id, obj.src);
|
var pluginRelativePath = path.join('plugins', plugin.id, obj.src);
|
||||||
removeFileAndParents(project.www, pluginRelativePath);
|
removeFileAndParents(project.www, pluginRelativePath);
|
||||||
if (options && options.usePlatformWww) {
|
if (options && options.usePlatformWww) {
|
||||||
// CB-11022 remove file from both directories if usePlatformWww is specified
|
// CB-11022 remove file from both directories if usePlatformWww is specified
|
||||||
@ -208,26 +235,29 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
|
|||||||
if (!fs.existsSync(src)) throw new CordovaError('"' + src + '" not found!');
|
if (!fs.existsSync(src)) throw new CordovaError('"' + src + '" not found!');
|
||||||
|
|
||||||
// check that src path is inside plugin directory
|
// check that src path is inside plugin directory
|
||||||
const real_path = fs.realpathSync(src);
|
var real_path = fs.realpathSync(src);
|
||||||
const real_plugin_path = fs.realpathSync(plugin_dir);
|
var real_plugin_path = fs.realpathSync(plugin_dir);
|
||||||
if (!isPathInside(real_path, real_plugin_path)) { throw new CordovaError('File "' + src + '" is located outside the plugin directory "' + plugin_dir + '"'); }
|
if (real_path.indexOf(real_plugin_path) !== 0) { throw new CordovaError('File "' + src + '" is located outside the plugin directory "' + plugin_dir + '"'); }
|
||||||
|
|
||||||
dest = path.resolve(project_dir, dest);
|
dest = path.resolve(project_dir, dest);
|
||||||
|
|
||||||
// check that dest path is located in project directory
|
// check that dest path is located in project directory
|
||||||
if (!isPathInside(dest, project_dir)) { throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project'); }
|
if (dest.indexOf(project_dir) !== 0) { throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project'); }
|
||||||
|
|
||||||
fs.ensureDirSync(path.dirname(dest));
|
shell.mkdir('-p', path.dirname(dest));
|
||||||
if (link) {
|
if (link) {
|
||||||
symlinkFileOrDirTree(src, dest);
|
symlinkFileOrDirTree(src, dest);
|
||||||
|
} else if (fs.statSync(src).isDirectory()) {
|
||||||
|
// XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
|
||||||
|
shell.cp('-Rf', src + '/*', dest);
|
||||||
} else {
|
} else {
|
||||||
fs.copySync(src, dest);
|
shell.cp('-f', src, dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same as copy file but throws error if target exists
|
// Same as copy file but throws error if target exists
|
||||||
function copyNewFile (plugin_dir, src, project_dir, dest, link) {
|
function copyNewFile (plugin_dir, src, project_dir, dest, link) {
|
||||||
const target_path = path.resolve(project_dir, dest);
|
var target_path = path.resolve(project_dir, dest);
|
||||||
if (fs.existsSync(target_path)) { throw new CordovaError('"' + target_path + '" already exists!'); }
|
if (fs.existsSync(target_path)) { throw new CordovaError('"' + target_path + '" already exists!'); }
|
||||||
|
|
||||||
copyFile(plugin_dir, src, project_dir, dest, !!link);
|
copyFile(plugin_dir, src, project_dir, dest, !!link);
|
||||||
@ -235,11 +265,11 @@ function copyNewFile (plugin_dir, src, project_dir, dest, link) {
|
|||||||
|
|
||||||
function symlinkFileOrDirTree (src, dest) {
|
function symlinkFileOrDirTree (src, dest) {
|
||||||
if (fs.existsSync(dest)) {
|
if (fs.existsSync(dest)) {
|
||||||
fs.removeSync(dest);
|
shell.rm('-Rf', dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.statSync(src).isDirectory()) {
|
if (fs.statSync(src).isDirectory()) {
|
||||||
fs.ensureDirSync(path.dirname(dest));
|
shell.mkdir('-p', dest);
|
||||||
fs.readdirSync(src).forEach(function (entry) {
|
fs.readdirSync(src).forEach(function (entry) {
|
||||||
symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
|
symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
|
||||||
});
|
});
|
||||||
@ -248,8 +278,15 @@ function symlinkFileOrDirTree (src, dest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFile (file) {
|
// checks if file exists and then deletes. Error if doesn't exist
|
||||||
fs.removeSync(file);
|
function removeFile (project_dir, src) {
|
||||||
|
var file = path.resolve(project_dir, src);
|
||||||
|
shell.rm('-Rf', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// deletes file/directory without checking
|
||||||
|
function removeFileF (file) {
|
||||||
|
shell.rm('-Rf', file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes we want to remove some java, and prune any unnecessary empty directories
|
// Sometimes we want to remove some java, and prune any unnecessary empty directories
|
||||||
@ -259,13 +296,13 @@ function deleteJava (project_dir, destFile) {
|
|||||||
|
|
||||||
function removeFileAndParents (baseDir, destFile, stopper) {
|
function removeFileAndParents (baseDir, destFile, stopper) {
|
||||||
stopper = stopper || '.';
|
stopper = stopper || '.';
|
||||||
const file = path.resolve(baseDir, destFile);
|
var file = path.resolve(baseDir, destFile);
|
||||||
if (!fs.existsSync(file)) return;
|
if (!fs.existsSync(file)) return;
|
||||||
|
|
||||||
removeFile(file);
|
removeFileF(file);
|
||||||
|
|
||||||
// check if directory is empty
|
// check if directory is empty
|
||||||
let curDir = path.dirname(file);
|
var curDir = path.dirname(file);
|
||||||
|
|
||||||
while (curDir !== path.resolve(baseDir, stopper)) {
|
while (curDir !== path.resolve(baseDir, stopper)) {
|
||||||
if (fs.existsSync(curDir) && fs.readdirSync(curDir).length === 0) {
|
if (fs.existsSync(curDir) && fs.readdirSync(curDir).length === 0) {
|
||||||
@ -281,44 +318,3 @@ function removeFileAndParents (baseDir, destFile, stopper) {
|
|||||||
function generateAttributeError (attribute, element, id) {
|
function generateAttributeError (attribute, element, id) {
|
||||||
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInstallDestination (obj) {
|
|
||||||
const APP_MAIN_PREFIX = 'app/src/main';
|
|
||||||
const PATH_SEPARATOR = '/';
|
|
||||||
|
|
||||||
const PATH_SEP_MATCH = '\\' + PATH_SEPARATOR;
|
|
||||||
const PATH_SEP_OR_EOL_MATCH = '(\\' + PATH_SEPARATOR + '|$)';
|
|
||||||
|
|
||||||
const appReg = new RegExp('^app' + PATH_SEP_OR_EOL_MATCH);
|
|
||||||
const libsReg = new RegExp('^libs' + PATH_SEP_OR_EOL_MATCH);
|
|
||||||
const srcReg = new RegExp('^src' + PATH_SEP_OR_EOL_MATCH);
|
|
||||||
const srcMainReg = new RegExp('^src' + PATH_SEP_MATCH + 'main' + PATH_SEP_OR_EOL_MATCH);
|
|
||||||
|
|
||||||
if (appReg.test(obj.targetDir)) {
|
|
||||||
// If any source file is using the new app directory structure,
|
|
||||||
// don't penalize it
|
|
||||||
return path.join(obj.targetDir, path.basename(obj.src));
|
|
||||||
} else {
|
|
||||||
// Plugin using deprecated target directory structure (GH-580)
|
|
||||||
if (obj.src.endsWith('.java')) {
|
|
||||||
return path.join(APP_MAIN_PREFIX, 'java', obj.targetDir.replace(srcReg, ''),
|
|
||||||
path.basename(obj.src));
|
|
||||||
} else if (obj.src.endsWith('.aidl')) {
|
|
||||||
return path.join(APP_MAIN_PREFIX, 'aidl', obj.targetDir.replace(srcReg, ''),
|
|
||||||
path.basename(obj.src));
|
|
||||||
} else if (libsReg.test(obj.targetDir)) {
|
|
||||||
if (obj.src.endsWith('.so')) {
|
|
||||||
return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.replace(libsReg, ''),
|
|
||||||
path.basename(obj.src));
|
|
||||||
} else {
|
|
||||||
return path.join('app', obj.targetDir, path.basename(obj.src));
|
|
||||||
}
|
|
||||||
} else if (srcMainReg.test(obj.targetDir)) {
|
|
||||||
return path.join('app', obj.targetDir, path.basename(obj.src));
|
|
||||||
}
|
|
||||||
|
|
||||||
// For all other source files not using the new app directory structure,
|
|
||||||
// add 'app/src/main' to the targetDir
|
|
||||||
return path.join(APP_MAIN_PREFIX, obj.targetDir, path.basename(obj.src));
|
|
||||||
}
|
|
||||||
}
|
|
480
bin/templates/cordova/lib/prepare.js
vendored
Normal file
@ -0,0 +1,480 @@
|
|||||||
|
/**
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
/* eslint no-useless-escape: 0 */
|
||||||
|
|
||||||
|
var Q = require('q');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var shell = require('shelljs');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
|
var checkReqs = require('./check_reqs');
|
||||||
|
var xmlHelpers = require('cordova-common').xmlHelpers;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var ConfigParser = require('cordova-common').ConfigParser;
|
||||||
|
var FileUpdater = require('cordova-common').FileUpdater;
|
||||||
|
var PlatformJson = require('cordova-common').PlatformJson;
|
||||||
|
var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger;
|
||||||
|
var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
|
||||||
|
|
||||||
|
module.exports.prepare = function (cordovaProject, options) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var platformJson = PlatformJson.load(this.locations.root, this.platform);
|
||||||
|
var munger = new PlatformMunger(this.platform, this.locations.root, platformJson, new PluginInfoProvider());
|
||||||
|
|
||||||
|
this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations);
|
||||||
|
|
||||||
|
// Update own www dir with project's www assets and plugins' assets and js-files
|
||||||
|
return Q.when(updateWww(cordovaProject, this.locations)).then(function () {
|
||||||
|
// update project according to config.xml changes.
|
||||||
|
return updateProjectAccordingTo(self._config, self.locations);
|
||||||
|
}).then(function () {
|
||||||
|
updateIcons(cordovaProject, path.relative(cordovaProject.root, self.locations.res));
|
||||||
|
updateSplashes(cordovaProject, path.relative(cordovaProject.root, self.locations.res));
|
||||||
|
updateFileResources(cordovaProject, path.relative(cordovaProject.root, self.locations.root));
|
||||||
|
}).then(function () {
|
||||||
|
events.emit('verbose', 'Prepared android project successfully');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.clean = function (options) {
|
||||||
|
// A cordovaProject isn't passed into the clean() function, because it might have
|
||||||
|
// been called from the platform shell script rather than the CLI. Check for the
|
||||||
|
// noPrepare option passed in by the non-CLI clean script. If that's present, or if
|
||||||
|
// there's no config.xml found at the project root, then don't clean prepared files.
|
||||||
|
var projectRoot = path.resolve(this.root, '../..');
|
||||||
|
if ((options && options.noPrepare) || !fs.existsSync(this.locations.configXml) ||
|
||||||
|
!fs.existsSync(this.locations.configXml)) {
|
||||||
|
return Q();
|
||||||
|
}
|
||||||
|
|
||||||
|
var projectConfig = new ConfigParser(this.locations.configXml);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return Q().then(function () {
|
||||||
|
cleanWww(projectRoot, self.locations);
|
||||||
|
cleanIcons(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
||||||
|
cleanSplashes(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
||||||
|
cleanFileResources(projectRoot, projectConfig, path.relative(projectRoot, self.locations.root));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates config files in project based on app's config.xml and config munge,
|
||||||
|
* generated by plugins.
|
||||||
|
*
|
||||||
|
* @param {ConfigParser} sourceConfig A project's configuration that will
|
||||||
|
* be merged into platform's config.xml
|
||||||
|
* @param {ConfigChanges} configMunger An initialized ConfigChanges instance
|
||||||
|
* for this platform.
|
||||||
|
* @param {Object} locations A map of locations for this platform
|
||||||
|
*
|
||||||
|
* @return {ConfigParser} An instance of ConfigParser, that
|
||||||
|
* represents current project's configuration. When returned, the
|
||||||
|
* configuration is already dumped to appropriate config.xml file.
|
||||||
|
*/
|
||||||
|
function updateConfigFilesFrom (sourceConfig, configMunger, locations) {
|
||||||
|
events.emit('verbose', 'Generating platform-specific config.xml from defaults for android at ' + locations.configXml);
|
||||||
|
|
||||||
|
// First cleanup current config and merge project's one into own
|
||||||
|
// Overwrite platform config.xml with defaults.xml.
|
||||||
|
shell.cp('-f', locations.defaultConfigXml, locations.configXml);
|
||||||
|
|
||||||
|
// Then apply config changes from global munge to all config files
|
||||||
|
// in project (including project's config)
|
||||||
|
configMunger.reapply_global_munge().save_all();
|
||||||
|
|
||||||
|
events.emit('verbose', 'Merging project\'s config.xml into platform-specific android config.xml');
|
||||||
|
// Merge changes from app's config.xml into platform's one
|
||||||
|
var config = new ConfigParser(locations.configXml);
|
||||||
|
xmlHelpers.mergeXml(sourceConfig.doc.getroot(),
|
||||||
|
config.doc.getroot(), 'android', /* clobber= */true);
|
||||||
|
|
||||||
|
config.write();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs all file operations via the verbose event stream, indented.
|
||||||
|
*/
|
||||||
|
function logFileOp (message) {
|
||||||
|
events.emit('verbose', ' ' + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates platform 'www' directory by replacing it with contents of
|
||||||
|
* 'platform_www' and app www. Also copies project's overrides' folder into
|
||||||
|
* the platform 'www' folder
|
||||||
|
*
|
||||||
|
* @param {Object} cordovaProject An object which describes cordova project.
|
||||||
|
* @param {Object} destinations An object that contains destination
|
||||||
|
* paths for www files.
|
||||||
|
*/
|
||||||
|
function updateWww (cordovaProject, destinations) {
|
||||||
|
var sourceDirs = [
|
||||||
|
path.relative(cordovaProject.root, cordovaProject.locations.www),
|
||||||
|
path.relative(cordovaProject.root, destinations.platformWww)
|
||||||
|
];
|
||||||
|
|
||||||
|
// If project contains 'merges' for our platform, use them as another overrides
|
||||||
|
var merges_path = path.join(cordovaProject.root, 'merges', 'android');
|
||||||
|
if (fs.existsSync(merges_path)) {
|
||||||
|
events.emit('verbose', 'Found "merges/android" folder. Copying its contents into the android project.');
|
||||||
|
sourceDirs.push(path.join('merges', 'android'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetDir = path.relative(cordovaProject.root, destinations.www);
|
||||||
|
events.emit(
|
||||||
|
'verbose', 'Merging and updating files from [' + sourceDirs.join(', ') + '] to ' + targetDir);
|
||||||
|
FileUpdater.mergeAndUpdateDir(
|
||||||
|
sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans all files from the platform 'www' directory.
|
||||||
|
*/
|
||||||
|
function cleanWww (projectRoot, locations) {
|
||||||
|
var targetDir = path.relative(projectRoot, locations.www);
|
||||||
|
events.emit('verbose', 'Cleaning ' + targetDir);
|
||||||
|
|
||||||
|
// No source paths are specified, so mergeAndUpdateDir() will clear the target directory.
|
||||||
|
FileUpdater.mergeAndUpdateDir(
|
||||||
|
[], targetDir, { rootDir: projectRoot, all: true }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates project structure and AndroidManifest according to project's configuration.
|
||||||
|
*
|
||||||
|
* @param {ConfigParser} platformConfig A project's configuration that will
|
||||||
|
* be used to update project
|
||||||
|
* @param {Object} locations A map of locations for this platform
|
||||||
|
*/
|
||||||
|
function updateProjectAccordingTo (platformConfig, locations) {
|
||||||
|
// Update app name by editing res/values/strings.xml
|
||||||
|
var strings = xmlHelpers.parseElementtreeSync(locations.strings);
|
||||||
|
|
||||||
|
var name = platformConfig.name();
|
||||||
|
strings.find('string[@name="app_name"]').text = name.replace(/\'/g, '\\\'');
|
||||||
|
|
||||||
|
var shortName = platformConfig.shortName && platformConfig.shortName();
|
||||||
|
if (shortName && shortName !== name) {
|
||||||
|
strings.find('string[@name="launcher_name"]').text = shortName.replace(/\'/g, '\\\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(locations.strings, strings.write({indent: 4}), 'utf-8');
|
||||||
|
events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
|
||||||
|
|
||||||
|
// Java packages cannot support dashes
|
||||||
|
var androidPkgName = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g, '_');
|
||||||
|
|
||||||
|
var manifest = new AndroidManifest(locations.manifest);
|
||||||
|
var manifestId = manifest.getPackageId();
|
||||||
|
|
||||||
|
manifest.getActivity()
|
||||||
|
.setOrientation(platformConfig.getPreference('orientation'))
|
||||||
|
.setLaunchMode(findAndroidLaunchModePreference(platformConfig));
|
||||||
|
|
||||||
|
manifest.setVersionName(platformConfig.version())
|
||||||
|
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
|
||||||
|
.setPackageId(androidPkgName)
|
||||||
|
.setMinSdkVersion(platformConfig.getPreference('android-minSdkVersion', 'android'))
|
||||||
|
.setMaxSdkVersion(platformConfig.getPreference('android-maxSdkVersion', 'android'))
|
||||||
|
.setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
|
||||||
|
.write();
|
||||||
|
|
||||||
|
// Java file paths shouldn't be hard coded
|
||||||
|
var javaPattern = path.join(locations.javaSrc, manifestId.replace(/\./g, '/'), '*.java');
|
||||||
|
var java_files = shell.ls(javaPattern).filter(function (f) {
|
||||||
|
return shell.grep(/extends\s+CordovaActivity/g, f);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (java_files.length === 0) {
|
||||||
|
throw new CordovaError('No Java files found that extend CordovaActivity.');
|
||||||
|
} else if (java_files.length > 1) {
|
||||||
|
events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found. Guessing at the first one, ' + java_files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var destFile = path.join(locations.root, 'app', 'src', 'main', 'java', androidPkgName.replace(/\./g, '/'), path.basename(java_files[0]));
|
||||||
|
shell.mkdir('-p', path.dirname(destFile));
|
||||||
|
shell.sed(/package [\w\.]*;/, 'package ' + androidPkgName + ';', java_files[0]).to(destFile);
|
||||||
|
events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + destFile);
|
||||||
|
|
||||||
|
var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() ?
|
||||||
|
manifestId.toUpperCase() !== androidPkgName.toUpperCase() :
|
||||||
|
manifestId !== androidPkgName;
|
||||||
|
|
||||||
|
if (removeOrigPkg) {
|
||||||
|
// If package was name changed we need to remove old java with main activity
|
||||||
|
shell.rm('-Rf', java_files[0]);
|
||||||
|
// remove any empty directories
|
||||||
|
var currentDir = path.dirname(java_files[0]);
|
||||||
|
var sourcesRoot = path.resolve(locations.root, 'src');
|
||||||
|
while (currentDir !== sourcesRoot) {
|
||||||
|
if (fs.existsSync(currentDir) && fs.readdirSync(currentDir).length === 0) {
|
||||||
|
fs.rmdirSync(currentDir);
|
||||||
|
currentDir = path.resolve(currentDir, '..');
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consturct the default value for versionCode as
|
||||||
|
// PATCH + MINOR * 100 + MAJOR * 10000
|
||||||
|
// see http://developer.android.com/tools/publishing/versioning.html
|
||||||
|
function default_versionCode (version) {
|
||||||
|
var nums = version.split('-')[0].split('.');
|
||||||
|
var versionCode = 0;
|
||||||
|
if (+nums[0]) {
|
||||||
|
versionCode += +nums[0] * 10000;
|
||||||
|
}
|
||||||
|
if (+nums[1]) {
|
||||||
|
versionCode += +nums[1] * 100;
|
||||||
|
}
|
||||||
|
if (+nums[2]) {
|
||||||
|
versionCode += +nums[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
events.emit('verbose', 'android-versionCode not found in config.xml. Generating a code based on version in config.xml (' + version + '): ' + versionCode);
|
||||||
|
return versionCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getImageResourcePath (resourcesDir, type, density, name, sourceName) {
|
||||||
|
if (/\.9\.png$/.test(sourceName)) {
|
||||||
|
name = name.replace(/\.png$/, '.9.png');
|
||||||
|
}
|
||||||
|
var resourcePath = path.join(resourcesDir, (density ? type + '-' + density : type), name);
|
||||||
|
return resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSplashes (cordovaProject, platformResourcesDir) {
|
||||||
|
var resources = cordovaProject.projectConfig.getSplashScreens('android');
|
||||||
|
|
||||||
|
// if there are "splash" elements in config.xml
|
||||||
|
if (resources.length === 0) {
|
||||||
|
events.emit('verbose', 'This app does not have splash screens defined');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resourceMap = mapImageResources(cordovaProject.root, platformResourcesDir, 'drawable', 'screen.png');
|
||||||
|
|
||||||
|
var hadMdpi = false;
|
||||||
|
resources.forEach(function (resource) {
|
||||||
|
if (!resource.density) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (resource.density === 'mdpi') {
|
||||||
|
hadMdpi = true;
|
||||||
|
}
|
||||||
|
var targetPath = getImageResourcePath(
|
||||||
|
platformResourcesDir, 'drawable', resource.density, 'screen.png', path.basename(resource.src));
|
||||||
|
resourceMap[targetPath] = resource.src;
|
||||||
|
});
|
||||||
|
|
||||||
|
// There's no "default" drawable, so assume default == mdpi.
|
||||||
|
if (!hadMdpi && resources.defaultResource) {
|
||||||
|
var targetPath = getImageResourcePath(
|
||||||
|
platformResourcesDir, 'drawable', 'mdpi', 'screen.png', path.basename(resources.defaultResource.src));
|
||||||
|
resourceMap[targetPath] = resources.defaultResource.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
events.emit('verbose', 'Updating splash screens at ' + platformResourcesDir);
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, { rootDir: cordovaProject.root }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanSplashes (projectRoot, projectConfig, platformResourcesDir) {
|
||||||
|
var resources = projectConfig.getSplashScreens('android');
|
||||||
|
if (resources.length > 0) {
|
||||||
|
var resourceMap = mapImageResources(projectRoot, platformResourcesDir, 'drawable', 'screen.png');
|
||||||
|
events.emit('verbose', 'Cleaning splash screens at ' + platformResourcesDir);
|
||||||
|
|
||||||
|
// No source paths are specified in the map, so updatePaths() will delete the target files.
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateIcons (cordovaProject, platformResourcesDir) {
|
||||||
|
var icons = cordovaProject.projectConfig.getIcons('android');
|
||||||
|
|
||||||
|
// if there are icon elements in config.xml
|
||||||
|
if (icons.length === 0) {
|
||||||
|
events.emit('verbose', 'This app does not have launcher icons defined');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resourceMap = mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'icon.png');
|
||||||
|
|
||||||
|
var android_icons = {};
|
||||||
|
var default_icon;
|
||||||
|
// http://developer.android.com/design/style/iconography.html
|
||||||
|
var sizeToDensityMap = {
|
||||||
|
36: 'ldpi',
|
||||||
|
48: 'mdpi',
|
||||||
|
72: 'hdpi',
|
||||||
|
96: 'xhdpi',
|
||||||
|
144: 'xxhdpi',
|
||||||
|
192: 'xxxhdpi'
|
||||||
|
};
|
||||||
|
// find the best matching icon for a given density or size
|
||||||
|
// @output android_icons
|
||||||
|
var parseIcon = function (icon, icon_size) {
|
||||||
|
// do I have a platform icon for that density already
|
||||||
|
var density = icon.density || sizeToDensityMap[icon_size];
|
||||||
|
if (!density) {
|
||||||
|
// invalid icon defition ( or unsupported size)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var previous = android_icons[density];
|
||||||
|
if (previous && previous.platform) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
android_icons[density] = icon;
|
||||||
|
};
|
||||||
|
|
||||||
|
// iterate over all icon elements to find the default icon and call parseIcon
|
||||||
|
for (var i = 0; i < icons.length; i++) {
|
||||||
|
var icon = icons[i];
|
||||||
|
var size = icon.width;
|
||||||
|
if (!size) {
|
||||||
|
size = icon.height;
|
||||||
|
}
|
||||||
|
if (!size && !icon.density) {
|
||||||
|
if (default_icon) {
|
||||||
|
events.emit('verbose', 'Found extra default icon: ' + icon.src + ' (ignoring in favor of ' + default_icon.src + ')');
|
||||||
|
} else {
|
||||||
|
default_icon = icon;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parseIcon(icon, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The source paths for icons and splashes are relative to
|
||||||
|
// project's config.xml location, so we use it as base path.
|
||||||
|
for (var density in android_icons) {
|
||||||
|
var targetPath = getImageResourcePath(
|
||||||
|
platformResourcesDir, 'mipmap', density, 'icon.png', path.basename(android_icons[density].src));
|
||||||
|
resourceMap[targetPath] = android_icons[density].src;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There's no "default" drawable, so assume default == mdpi.
|
||||||
|
if (default_icon && !android_icons.mdpi) {
|
||||||
|
var defaultTargetPath = getImageResourcePath(
|
||||||
|
platformResourcesDir, 'mipmap', 'mdpi', 'icon.png', path.basename(default_icon.src));
|
||||||
|
resourceMap[defaultTargetPath] = default_icon.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
events.emit('verbose', 'Updating icons at ' + platformResourcesDir);
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, { rootDir: cordovaProject.root }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanIcons (projectRoot, projectConfig, platformResourcesDir) {
|
||||||
|
var icons = projectConfig.getIcons('android');
|
||||||
|
if (icons.length > 0) {
|
||||||
|
var resourceMap = mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'icon.png');
|
||||||
|
events.emit('verbose', 'Cleaning icons at ' + platformResourcesDir);
|
||||||
|
|
||||||
|
// No source paths are specified in the map, so updatePaths() will delete the target files.
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a map containing resources of a specified name from all drawable folders in a directory.
|
||||||
|
*/
|
||||||
|
function mapImageResources (rootDir, subDir, type, resourceName) {
|
||||||
|
var pathMap = {};
|
||||||
|
shell.ls(path.join(rootDir, subDir, type + '-*')).forEach(function (drawableFolder) {
|
||||||
|
var imagePath = path.join(subDir, path.basename(drawableFolder), resourceName);
|
||||||
|
pathMap[imagePath] = null;
|
||||||
|
});
|
||||||
|
return pathMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFileResources (cordovaProject, platformDir) {
|
||||||
|
var files = cordovaProject.projectConfig.getFileResources('android');
|
||||||
|
|
||||||
|
// if there are resource-file elements in config.xml
|
||||||
|
if (files.length === 0) {
|
||||||
|
events.emit('verbose', 'This app does not have additional resource files defined');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resourceMap = {};
|
||||||
|
files.forEach(function (res) {
|
||||||
|
var targetPath = path.join(platformDir, res.target);
|
||||||
|
resourceMap[targetPath] = res.src;
|
||||||
|
});
|
||||||
|
|
||||||
|
events.emit('verbose', 'Updating resource files at ' + platformDir);
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, { rootDir: cordovaProject.root }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanFileResources (projectRoot, projectConfig, platformDir) {
|
||||||
|
var files = projectConfig.getFileResources('android', true);
|
||||||
|
if (files.length > 0) {
|
||||||
|
events.emit('verbose', 'Cleaning resource files at ' + platformDir);
|
||||||
|
|
||||||
|
var resourceMap = {};
|
||||||
|
files.forEach(function (res) {
|
||||||
|
var filePath = path.join(platformDir, res.target);
|
||||||
|
resourceMap[filePath] = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
FileUpdater.updatePaths(
|
||||||
|
resourceMap, {
|
||||||
|
rootDir: projectRoot, all: true}, logFileOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets and validates 'AndroidLaunchMode' prepference from config.xml. Returns
|
||||||
|
* preference value and warns if it doesn't seems to be valid
|
||||||
|
*
|
||||||
|
* @param {ConfigParser} platformConfig A configParser instance for
|
||||||
|
* platform.
|
||||||
|
*
|
||||||
|
* @return {String} Preference's value from config.xml or
|
||||||
|
* default value, if there is no such preference. The default value is
|
||||||
|
* 'singleTop'
|
||||||
|
*/
|
||||||
|
function findAndroidLaunchModePreference (platformConfig) {
|
||||||
|
var launchMode = platformConfig.getPreference('AndroidLaunchMode');
|
||||||
|
if (!launchMode) {
|
||||||
|
// Return a default value
|
||||||
|
return 'singleTop';
|
||||||
|
}
|
||||||
|
|
||||||
|
var expectedValues = ['standard', 'singleTop', 'singleTask', 'singleInstance'];
|
||||||
|
var valid = expectedValues.indexOf(launchMode) >= 0;
|
||||||
|
if (!valid) {
|
||||||
|
// Note: warn, but leave the launch mode as developer wanted, in case the list of options changes in the future
|
||||||
|
events.emit('warn', 'Unrecognized value for AndroidLaunchMode preference: ' +
|
||||||
|
launchMode + '. Expected values are: ' + expectedValues.join(', '));
|
||||||
|
}
|
||||||
|
|
||||||
|
return launchMode;
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
@ -17,27 +19,50 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* jshint node: true */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Retry a promise-returning function a number of times, propagating its
|
* Retry a promise-returning function a number of times, propagating its
|
||||||
* results on success or throwing its error on a failed final attempt.
|
* results on success or throwing its error on a failed final attempt.
|
||||||
*
|
*
|
||||||
* @arg {Number} attemptsLeft - The number of times to retry the passed call.
|
* @arg {Number} attemts_left - The number of times to retry the passed call.
|
||||||
* @arg {Function} promiseFunction - A function that returns a promise.
|
* @arg {Function} promiseFunction - A function that returns a promise.
|
||||||
* @arg {...} - Arguments to pass to promiseFunction.
|
* @arg {...} - Arguments to pass to promiseFunction.
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
module.exports.retryPromise = async function (attemptsLeft, promiseFunction, ...args) {
|
module.exports.retryPromise = function (attemts_left, promiseFunction) {
|
||||||
while (true) {
|
|
||||||
try {
|
// NOTE:
|
||||||
return await promiseFunction(...args);
|
// get all trailing arguments, by skipping the first two (attemts_left and
|
||||||
} catch (error) {
|
// promiseFunction) because they shouldn't get passed to promiseFunction
|
||||||
if (--attemptsLeft < 1) throw error;
|
var promiseFunctionArguments = Array.prototype.slice.call(arguments, 2);
|
||||||
events.emit('verbose', 'A retried call failed. Retrying ' + attemptsLeft + ' more time(s).');
|
|
||||||
|
return promiseFunction.apply(undefined, promiseFunctionArguments).then(
|
||||||
|
|
||||||
|
// on success pass results through
|
||||||
|
function onFulfilled (value) {
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
|
// on rejection either retry, or throw the error
|
||||||
|
function onRejected (error) {
|
||||||
|
|
||||||
|
attemts_left -= 1;
|
||||||
|
|
||||||
|
if (attemts_left < 1) {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.emit('verbose', 'A retried call failed. Retrying ' + attemts_left + ' more time(s).');
|
||||||
|
|
||||||
|
// retry call self again with the same arguments, except attemts_left is now lower
|
||||||
|
var fullArguments = [attemts_left, promiseFunction].concat(promiseFunctionArguments);
|
||||||
|
return module.exports.retryPromise.apply(undefined, fullArguments);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
};
|
};
|
132
bin/templates/cordova/lib/run.js
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* jshint loopfunc:true */
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
|
var build = require('./build');
|
||||||
|
var emulator = require('./emulator');
|
||||||
|
var device = require('./device');
|
||||||
|
var Q = require('q');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
|
||||||
|
function getInstallTarget (runOptions) {
|
||||||
|
var install_target;
|
||||||
|
if (runOptions.target) {
|
||||||
|
install_target = runOptions.target;
|
||||||
|
} else if (runOptions.device) {
|
||||||
|
install_target = '--device';
|
||||||
|
} else if (runOptions.emulator) {
|
||||||
|
install_target = '--emulator';
|
||||||
|
}
|
||||||
|
|
||||||
|
return install_target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the application on a device if available. If no device is found, it will
|
||||||
|
* use a started emulator. If no started emulators are found it will attempt
|
||||||
|
* to start an avd. If no avds are found it will error out.
|
||||||
|
*
|
||||||
|
* @param {Object} runOptions various run/build options. See Api.js build/run
|
||||||
|
* methods for reference.
|
||||||
|
*
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
module.exports.run = function (runOptions) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
var install_target = getInstallTarget(runOptions);
|
||||||
|
|
||||||
|
return Q().then(function () {
|
||||||
|
if (!install_target) {
|
||||||
|
// no target given, deploy to device if available, otherwise use the emulator.
|
||||||
|
return device.list().then(function (device_list) {
|
||||||
|
if (device_list.length > 0) {
|
||||||
|
events.emit('warn', 'No target specified, deploying to device \'' + device_list[0] + '\'.');
|
||||||
|
install_target = device_list[0];
|
||||||
|
} else {
|
||||||
|
events.emit('warn', 'No target specified and no devices found, deploying to emulator');
|
||||||
|
install_target = '--emulator';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).then(function () {
|
||||||
|
if (install_target === '--device') {
|
||||||
|
return device.resolveTarget(null);
|
||||||
|
} else if (install_target === '--emulator') {
|
||||||
|
// Give preference to any already started emulators. Else, start one.
|
||||||
|
return emulator.list_started().then(function (started) {
|
||||||
|
return started && started.length > 0 ? started[0] : emulator.start();
|
||||||
|
}).then(function (emulatorId) {
|
||||||
|
return emulator.resolveTarget(emulatorId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// They specified a specific device/emulator ID.
|
||||||
|
return device.list().then(function (devices) {
|
||||||
|
if (devices.indexOf(install_target) > -1) {
|
||||||
|
return device.resolveTarget(install_target);
|
||||||
|
}
|
||||||
|
return emulator.list_started().then(function (started_emulators) {
|
||||||
|
if (started_emulators.indexOf(install_target) > -1) {
|
||||||
|
return emulator.resolveTarget(install_target);
|
||||||
|
}
|
||||||
|
return emulator.list_images().then(function (avds) {
|
||||||
|
// if target emulator isn't started, then start it.
|
||||||
|
for (var avd in avds) {
|
||||||
|
if (avds[avd].name === install_target) {
|
||||||
|
return emulator.start(install_target).then(function (emulatorId) {
|
||||||
|
return emulator.resolveTarget(emulatorId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Q.reject('Target \'' + install_target + '\' not found, unable to run project');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).then(function (resolvedTarget) {
|
||||||
|
// Better just call self.build, but we're doing some processing of
|
||||||
|
// build results (according to platformApi spec) so they are in different
|
||||||
|
// format than emulator.install expects.
|
||||||
|
// TODO: Update emulator/device.install to handle this change
|
||||||
|
return build.run.call(self, runOptions, resolvedTarget).then(function (buildResults) {
|
||||||
|
if (resolvedTarget.isEmulator) {
|
||||||
|
return emulator.wait_for_boot(resolvedTarget.target).then(function () {
|
||||||
|
return emulator.install(resolvedTarget, buildResults);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return device.install(resolvedTarget, buildResults);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.help = function () {
|
||||||
|
console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]) + ' [options]');
|
||||||
|
console.log('Build options :');
|
||||||
|
console.log(' --debug : Builds project in debug mode');
|
||||||
|
console.log(' --release : Builds project in release mode');
|
||||||
|
console.log(' --nobuild : Runs the currently built project without recompiling');
|
||||||
|
console.log('Deploy options :');
|
||||||
|
console.log(' --device : Will deploy the built project to a device');
|
||||||
|
console.log(' --emulator : Will deploy the built project to an emulator if one exists');
|
||||||
|
console.log(' --target=<target_id> : Installs to the target with the specified id.');
|
||||||
|
process.exit(0);
|
||||||
|
};
|
39
bin/templates/cordova/lib/start-emulator
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var emulator = require('./emulator'),
|
||||||
|
args = process.argv;
|
||||||
|
|
||||||
|
var install_target;
|
||||||
|
if(args.length > 2) {
|
||||||
|
if (args[2].substring(0, 9) == '--target=') {
|
||||||
|
install_target = args[2].substring(9, args[2].length);
|
||||||
|
} else {
|
||||||
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emulator.start(install_target).done(null, function(err) {
|
||||||
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
||||||
|
|
26
bin/templates/cordova/lib/start-emulator.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0start-emulator"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'start-emulator' script in 'cordova\lib' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
32
framework/src/org/apache/cordova/CordovaPluginPathHandler.java → bin/templates/cordova/log
Normal file → Executable file
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
@ -17,22 +19,18 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.cordova;
|
var log = require('./lib/log'),
|
||||||
|
reqs = require('./lib/check_reqs'),
|
||||||
|
args = process.argv;
|
||||||
|
|
||||||
import androidx.webkit.WebViewAssetLoader;
|
// Usage support for when args are given
|
||||||
|
if(args.length > 2) {
|
||||||
/**
|
log.help();
|
||||||
* Wrapper class for path and handler
|
} else {
|
||||||
*/
|
reqs.run().done(function() {
|
||||||
public class CordovaPluginPathHandler {
|
return log.run();
|
||||||
|
}, function(err) {
|
||||||
private final WebViewAssetLoader.PathHandler handler;
|
console.error('ERROR: ' + err);
|
||||||
|
process.exit(2);
|
||||||
public CordovaPluginPathHandler(WebViewAssetLoader.PathHandler handler) {
|
});
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebViewAssetLoader.PathHandler getPathHandler() {
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,5 +16,11 @@
|
|||||||
:: under the License.
|
:: under the License.
|
||||||
|
|
||||||
@ECHO OFF
|
@ECHO OFF
|
||||||
for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Android Studio" /v Path') do set "ASPath=%%~b"
|
SET script_path="%~dp0log"
|
||||||
ECHO %ASPath%
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'log' script in 'cordova' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
18
bin/templates/cordova/loggingHelper.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
var CordovaLogger = require('cordova-common').CordovaLogger;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
adjustLoggerLevel: function (opts) {
|
||||||
|
if (opts instanceof Array) {
|
||||||
|
opts.silent = opts.indexOf('--silent') !== -1;
|
||||||
|
opts.verbose = opts.indexOf('--verbose') !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.silent) {
|
||||||
|
CordovaLogger.get().setLevel('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.verbose) {
|
||||||
|
CordovaLogger.get().setLevel('verbose');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
53
bin/templates/cordova/run
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Api = require('./Api');
|
||||||
|
var nopt = require('nopt');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
// Support basic help commands
|
||||||
|
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0)
|
||||||
|
require('./lib/run').help();
|
||||||
|
|
||||||
|
// Do some basic argument parsing
|
||||||
|
var runOpts = nopt({
|
||||||
|
'verbose' : Boolean,
|
||||||
|
'silent' : Boolean,
|
||||||
|
'debug' : Boolean,
|
||||||
|
'release' : Boolean,
|
||||||
|
'nobuild': Boolean,
|
||||||
|
'buildConfig' : path,
|
||||||
|
'archs' : String,
|
||||||
|
'device' : Boolean,
|
||||||
|
'emulator': Boolean,
|
||||||
|
'target' : String
|
||||||
|
}, { 'd' : '--verbose' });
|
||||||
|
|
||||||
|
// Make runOptions compatible with PlatformApi run method spec
|
||||||
|
runOpts.argv = runOpts.argv.remain;
|
||||||
|
|
||||||
|
require('./loggingHelper').adjustLoggerLevel(runOpts);
|
||||||
|
|
||||||
|
new Api().run(runOpts)
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error(err, err.stack);
|
||||||
|
process.exit(2);
|
||||||
|
});
|
26
bin/templates/cordova/run.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0run"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'run' script in 'cordova' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
@ -19,6 +19,11 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Api = require('./Api');
|
// Coho updates this line:
|
||||||
|
var VERSION = "7.0.0";
|
||||||
|
|
||||||
console.log(Api.version());
|
module.exports.version = VERSION;
|
||||||
|
|
||||||
|
if (!module.parent) {
|
||||||
|
console.log(VERSION);
|
||||||
|
}
|
26
bin/templates/cordova/version.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
:: or more contributor license agreements. See the NOTICE file
|
||||||
|
:: distributed with this work for additional information
|
||||||
|
:: regarding copyright ownership. The ASF licenses this file
|
||||||
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
|
:: "License"); you may not use this file except in compliance
|
||||||
|
:: with the License. You may obtain a copy of the License at
|
||||||
|
::
|
||||||
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
::
|
||||||
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
|
:: software distributed under the License is distributed on an
|
||||||
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
:: KIND, either express or implied. See the License for the
|
||||||
|
:: specific language governing permissions and limitations
|
||||||
|
:: under the License.
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
SET script_path="%~dp0version"
|
||||||
|
IF EXIST %script_path% (
|
||||||
|
node %script_path% %*
|
||||||
|
) ELSE (
|
||||||
|
ECHO.
|
||||||
|
ECHO ERROR: Could not find 'version' script in 'cordova' folder, aborting...>&2
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
@ -20,7 +20,6 @@
|
|||||||
package __ID__;
|
package __ID__;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.apache.cordova.*;
|
import org.apache.cordova.*;
|
||||||
|
|
||||||
public class __ACTIVITY__ extends CordovaActivity
|
public class __ACTIVITY__ extends CordovaActivity
|
@ -18,9 +18,7 @@
|
|||||||
under the License.
|
under the License.
|
||||||
-->
|
-->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:versionName="1.0"
|
package="__PACKAGE__" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
|
||||||
android:versionCode="1"
|
|
||||||
android:hardwareAccelerated="true">
|
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:largeScreens="true"
|
android:largeScreens="true"
|
||||||
android:normalScreens="true"
|
android:normalScreens="true"
|
||||||
@ -32,19 +30,20 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
|
<application android:icon="@mipmap/icon" android:label="@string/app_name"
|
||||||
android:hardwareAccelerated="true" android:supportsRtl="true">
|
android:hardwareAccelerated="true" android:supportsRtl="true">
|
||||||
<activity android:name="__ACTIVITY__"
|
<activity android:name="__ACTIVITY__"
|
||||||
android:label="@string/activity_name"
|
android:label="@string/activity_name"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:theme="@style/Theme.App.SplashScreen"
|
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
|
||||||
android:exported="true">
|
|
||||||
<intent-filter android:label="@string/launcher_name">
|
<intent-filter android:label="@string/launcher_name">
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="__APILEVEL__"/>
|
||||||
</manifest>
|
</manifest>
|
@ -19,70 +19,52 @@
|
|||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
|
|
||||||
apply plugin: 'kotlin-android'
|
|
||||||
apply plugin: 'kotlin-android-extensions'
|
|
||||||
}
|
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
apply from: '../CordovaLib/cordova.gradle'
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
// Checks if the kotlin version format is valid.
|
jcenter()
|
||||||
if(cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
|
maven {
|
||||||
if(!cdvHelpers.isVersionValid(cordovaConfig.KOTLIN_VERSION)) {
|
url "https://maven.google.com"
|
||||||
throw new GradleException("The defined Kotlin version (${cordovaConfig.KOTLIN_VERSION}) does not appear to be a valid version.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: 'repositories.gradle'
|
|
||||||
repositories repos
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
|
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||||
|
|
||||||
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cordovaConfig.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED) {
|
|
||||||
// Checks if the kotlin version format is valid.
|
|
||||||
if(!cdvHelpers.isVersionValid(cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION)) {
|
|
||||||
throw new GradleException("The defined Google Services plugin version (${cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION}) does not appear to be a valid version.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the Google Services classpath and set it.
|
|
||||||
String gradlePluginGoogleServicesClassPath = "com.google.gms:google-services:${cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION}"
|
|
||||||
println "Adding classpath: ${gradlePluginGoogleServicesClassPath}"
|
|
||||||
classpath gradlePluginGoogleServicesClassPath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow plugins to declare Maven dependencies via build-extras.gradle.
|
// Allow plugins to declare Maven dependencies via build-extras.gradle.
|
||||||
allprojects {
|
allprojects {
|
||||||
def hasRepositoriesGradle = file('repositories.gradle').exists()
|
repositories {
|
||||||
if (hasRepositoriesGradle) {
|
mavenCentral();
|
||||||
apply from: 'repositories.gradle'
|
jcenter()
|
||||||
} else {
|
|
||||||
apply from: "${project.rootDir}/repositories.gradle"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories repos
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
gradleVersion = cordovaConfig.GRADLE_VERSION
|
gradleVersion = '4.1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
|
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
|
||||||
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
|
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
|
||||||
ext {
|
ext {
|
||||||
apply from: '../CordovaLib/cordova.gradle'
|
apply from: '../CordovaLib/cordova.gradle'
|
||||||
|
// The value for android.compileSdkVersion.
|
||||||
|
if (!project.hasProperty('cdvCompileSdkVersion')) {
|
||||||
|
cdvCompileSdkVersion = null;
|
||||||
|
}
|
||||||
|
// The value for android.buildToolsVersion.
|
||||||
|
if (!project.hasProperty('cdvBuildToolsVersion')) {
|
||||||
|
cdvBuildToolsVersion = null;
|
||||||
|
}
|
||||||
// Sets the versionCode to the given value.
|
// Sets the versionCode to the given value.
|
||||||
if (!project.hasProperty('cdvVersionCode')) {
|
if (!project.hasProperty('cdvVersionCode')) {
|
||||||
cdvVersionCode = null
|
cdvVersionCode = null
|
||||||
}
|
}
|
||||||
|
// Sets the minSdkVersion to the given value.
|
||||||
|
if (!project.hasProperty('cdvMinSdkVersion')) {
|
||||||
|
cdvMinSdkVersion = null
|
||||||
|
}
|
||||||
// Whether to build architecture-specific APKs.
|
// Whether to build architecture-specific APKs.
|
||||||
if (!project.hasProperty('cdvBuildMultipleApks')) {
|
if (!project.hasProperty('cdvBuildMultipleApks')) {
|
||||||
cdvBuildMultipleApks = null
|
cdvBuildMultipleApks = null
|
||||||
@ -111,20 +93,20 @@ ext {
|
|||||||
// PLUGIN GRADLE EXTENSIONS START
|
// PLUGIN GRADLE EXTENSIONS START
|
||||||
// PLUGIN GRADLE EXTENSIONS END
|
// PLUGIN GRADLE EXTENSIONS END
|
||||||
|
|
||||||
def hasBuildExtras1 = file('build-extras.gradle').exists()
|
def hasBuildExtras = file('build-extras.gradle').exists()
|
||||||
if (hasBuildExtras1) {
|
if (hasBuildExtras) {
|
||||||
apply from: 'build-extras.gradle'
|
apply from: 'build-extras.gradle'
|
||||||
}
|
}
|
||||||
|
|
||||||
def hasBuildExtras2 = file('../build-extras.gradle').exists()
|
|
||||||
if (hasBuildExtras2) {
|
|
||||||
apply from: '../build-extras.gradle'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply updates that might come from build-extra.
|
|
||||||
privateHelpers.applyCordovaConfigCustomization()
|
|
||||||
|
|
||||||
// Set property defaults after extension .gradle files.
|
// Set property defaults after extension .gradle files.
|
||||||
|
if (ext.cdvCompileSdkVersion == null) {
|
||||||
|
ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
|
||||||
|
//ext.cdvCompileSdkVersion = project.ext.defaultCompileSdkVersion
|
||||||
|
}
|
||||||
|
if (ext.cdvBuildToolsVersion == null) {
|
||||||
|
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
|
||||||
|
//ext.cdvBuildToolsVersion = project.ext.defaultBuildToolsVersion
|
||||||
|
}
|
||||||
if (ext.cdvDebugSigningPropertiesFile == null && file('../debug-signing.properties').exists()) {
|
if (ext.cdvDebugSigningPropertiesFile == null && file('../debug-signing.properties').exists()) {
|
||||||
ext.cdvDebugSigningPropertiesFile = '../debug-signing.properties'
|
ext.cdvDebugSigningPropertiesFile = '../debug-signing.properties'
|
||||||
}
|
}
|
||||||
@ -135,6 +117,7 @@ if (ext.cdvReleaseSigningPropertiesFile == null && file('../release-signing.prop
|
|||||||
// Cast to appropriate types.
|
// Cast to appropriate types.
|
||||||
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
|
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
|
||||||
ext.cdvVersionCodeForceAbiDigit = cdvVersionCodeForceAbiDigit == null ? false : cdvVersionCodeForceAbiDigit.toBoolean();
|
ext.cdvVersionCodeForceAbiDigit = cdvVersionCodeForceAbiDigit == null ? false : cdvVersionCodeForceAbiDigit.toBoolean();
|
||||||
|
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : defaultMinSdkVersion
|
||||||
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
|
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
|
||||||
|
|
||||||
def computeBuildTargetName(debugBuild) {
|
def computeBuildTargetName(debugBuild) {
|
||||||
@ -157,53 +140,44 @@ cdvBuildRelease.dependsOn {
|
|||||||
return computeBuildTargetName(false)
|
return computeBuildTargetName(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
task cdvPrintProps {
|
task cdvPrintProps << {
|
||||||
doLast {
|
println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
|
||||||
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
|
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
|
||||||
println('cdvVersionCode=' + cdvVersionCode)
|
println('cdvVersionCode=' + cdvVersionCode)
|
||||||
println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
|
println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
|
||||||
println('cdvSdkVersion=' + cdvSdkVersion)
|
|
||||||
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
|
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
|
||||||
println('cdvMaxSdkVersion=' + cdvMaxSdkVersion)
|
|
||||||
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
|
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
|
||||||
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
|
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
|
||||||
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
|
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
|
||||||
println('cdvBuildArch=' + cdvBuildArch)
|
println('cdvBuildArch=' + cdvBuildArch)
|
||||||
println('computedVersionCode=' + android.defaultConfig.versionCode)
|
println('computedVersionCode=' + android.defaultConfig.versionCode)
|
||||||
println('cdvAndroidXAppCompatVersion=' + cdvAndroidXAppCompatVersion)
|
|
||||||
println('cdvAndroidXWebKitVersion=' + cdvAndroidXWebKitVersion)
|
|
||||||
android.productFlavors.each { flavor ->
|
android.productFlavors.each { flavor ->
|
||||||
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
|
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace cordovaConfig.PACKAGE_NAMESPACE
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
|
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
|
||||||
applicationId cordovaConfig.PACKAGE_NAMESPACE
|
applicationId privateHelpers.extractStringFromManifest("package")
|
||||||
|
|
||||||
minSdkVersion cordovaConfig.MIN_SDK_VERSION
|
if (cdvMinSdkVersion != null) {
|
||||||
if (cordovaConfig.MAX_SDK_VERSION != null) {
|
minSdkVersion cdvMinSdkVersion
|
||||||
maxSdkVersion cordovaConfig.MAX_SDK_VERSION
|
|
||||||
}
|
}
|
||||||
targetSdkVersion cordovaConfig.SDK_VERSION
|
|
||||||
compileSdkVersion cordovaConfig.COMPILE_SDK_VERSION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
abortOnError false
|
abortOnError false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION
|
compileSdkVersion cdvCompileSdkVersion
|
||||||
|
buildToolsVersion cdvBuildToolsVersion
|
||||||
|
|
||||||
// This code exists for Crosswalk and other Native APIs.
|
//This code exists for Crosswalk and other Native APIs.
|
||||||
// By default, we multiply the existing version code in the
|
//By default, we multiply the existing version code in the Android Manifest by 10 and
|
||||||
// Android Manifest by 10 and add a number for each architecture.
|
//add a number for each architecture. If you are not using Crosswalk or SQLite, you can
|
||||||
// If you are not using Crosswalk or SQLite, you can
|
//ignore this chunk of code, and your version codes will be respected.
|
||||||
// ignore this chunk of code, and your version codes will be respected.
|
|
||||||
|
|
||||||
if (Boolean.valueOf(cdvBuildMultipleApks)) {
|
if (Boolean.valueOf(cdvBuildMultipleApks)) {
|
||||||
flavorDimensions "default"
|
flavorDimensions "default"
|
||||||
@ -257,9 +231,9 @@ android {
|
|||||||
release {
|
release {
|
||||||
// These must be set or Gradle will complain (even if they are overridden).
|
// These must be set or Gradle will complain (even if they are overridden).
|
||||||
keyAlias = ""
|
keyAlias = ""
|
||||||
keyPassword = ""
|
keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
|
||||||
storeFile = null
|
storeFile = null
|
||||||
storePassword = ""
|
storePassword = "__unset"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@ -269,14 +243,9 @@ android {
|
|||||||
}
|
}
|
||||||
addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
|
addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cdvDebugSigningPropertiesFile) {
|
if (cdvDebugSigningPropertiesFile) {
|
||||||
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
|
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main.java.srcDirs += 'src/main/kotlin'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -288,19 +257,32 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||||
implementation "androidx.appcompat:appcompat:${cordovaConfig.ANDROIDX_APP_COMPAT_VERSION}"
|
|
||||||
implementation "androidx.core:core-splashscreen:${cordovaConfig.ANDROIDX_CORE_SPLASHSCREEN_VERSION}"
|
|
||||||
|
|
||||||
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${cordovaConfig.KOTLIN_VERSION}"
|
|
||||||
}
|
|
||||||
|
|
||||||
// SUB-PROJECT DEPENDENCIES START
|
// SUB-PROJECT DEPENDENCIES START
|
||||||
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
|
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
|
||||||
releaseCompile(project(path: ":CordovaLib", configuration: "release"))
|
releaseCompile(project(path: ":CordovaLib", configuration: "release"))
|
||||||
// SUB-PROJECT DEPENDENCIES END
|
// SUB-PROJECT DEPENDENCIES END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def promptForReleaseKeyPassword() {
|
||||||
|
if (!cdvReleaseSigningPropertiesFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
|
||||||
|
android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
|
||||||
|
}
|
||||||
|
if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
|
||||||
|
android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle.taskGraph.whenReady { taskGraph ->
|
||||||
|
taskGraph.getAllTasks().each() { task ->
|
||||||
|
if(['validateReleaseSigning', 'validateSigningRelease', 'validateSigningArmv7Release', 'validateSigningX76Release'].contains(task.name)) {
|
||||||
|
promptForReleaseKeyPassword()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def addSigningProps(propsFilePath, signingConfig) {
|
def addSigningProps(propsFilePath, signingConfig) {
|
||||||
def propsFile = file(propsFilePath)
|
def propsFile = file(propsFilePath)
|
||||||
def props = new Properties()
|
def props = new Properties()
|
||||||
@ -321,7 +303,7 @@ def addSigningProps(propsFilePath, signingConfig) {
|
|||||||
signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
|
signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
|
||||||
def storeType = props.get('storeType', props.get('key.store.type', ''))
|
def storeType = props.get('storeType', props.get('key.store.type', ''))
|
||||||
if (!storeType) {
|
if (!storeType) {
|
||||||
def filename = storeFile.getName().toLowerCase()
|
def filename = storeFile.getName().toLowerCase();
|
||||||
if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
|
if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
|
||||||
storeType = 'pkcs12'
|
storeType = 'pkcs12'
|
||||||
} else {
|
} else {
|
||||||
@ -340,7 +322,3 @@ for (def func : cdvPluginPostBuildExtras) {
|
|||||||
if (hasProperty('postBuildExtras')) {
|
if (hasProperty('postBuildExtras')) {
|
||||||
postBuildExtras()
|
postBuildExtras()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cordovaConfig.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED) {
|
|
||||||
apply plugin: 'com.google.gms.google-services'
|
|
||||||
}
|
|
2188
bin/templates/project/assets/www/cordova.js
vendored
Normal file
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@ -21,7 +21,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<!--
|
<!--
|
||||||
Customize this policy to fit your own app's needs. For more guidance, see:
|
Customize this policy to fit your own app's needs. For more guidance, see:
|
||||||
https://cordova.apache.org/docs/en/latest/
|
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
|
||||||
Some notes:
|
Some notes:
|
||||||
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
|
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
|
||||||
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
|
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
|
@ -17,29 +17,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
apply from: 'CordovaLib/cordova.gradle'
|
repositories {
|
||||||
apply from: 'repositories.gradle'
|
jcenter()
|
||||||
repositories repos
|
maven {
|
||||||
|
url "https://maven.google.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
cdvHelpers.verifyCordovaConfigForBuild()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
def hasRepositoriesGradle = file('repositories.gradle').exists()
|
repositories {
|
||||||
if (hasRepositoriesGradle) {
|
jcenter()
|
||||||
apply from: 'repositories.gradle'
|
maven {
|
||||||
} else {
|
url "https://maven.google.com"
|
||||||
apply from: "${project.rootDir}/repositories.gradle"
|
}
|
||||||
|
}
|
||||||
|
//This replaces project.properties w.r.t. build settings
|
||||||
|
project.ext {
|
||||||
|
defaultBuildToolsVersion="25.0.2" //String
|
||||||
|
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
|
||||||
|
defaultTargetSdkVersion=26 //Integer - We ALWAYS target the latest by default
|
||||||
|
defaultCompileSdkVersion=26 //Integer - We ALWAYS compile with the latest by default
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories repos
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
task clean(type: Delete) {
|
@ -10,12 +10,5 @@ ant-gen
|
|||||||
# Eclipse builds
|
# Eclipse builds
|
||||||
gen
|
gen
|
||||||
out
|
out
|
||||||
# Gradle build artifacts
|
# Gradle builds
|
||||||
.gradle
|
|
||||||
.gradletasknamecache
|
|
||||||
/build
|
/build
|
||||||
/CordovaLib/build
|
|
||||||
/app/build
|
|
||||||
gradle-app.setting
|
|
||||||
# Android Studio
|
|
||||||
.idea
|
|
311
bin/templates/project/legacy/build.gradle
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch the Android Gradle plugin version requirement depending on the
|
||||||
|
// installed version of Gradle. This dependency is documented at
|
||||||
|
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
|
||||||
|
// and https://issues.apache.org/jira/browse/CB-8143
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow plugins to declare Maven dependencies via build-extras.gradle.
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenCentral();
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task wrapper(type: Wrapper) {
|
||||||
|
gradleVersion = '2.14.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
|
||||||
|
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
|
||||||
|
ext {
|
||||||
|
apply from: 'CordovaLib/cordova.gradle'
|
||||||
|
// The value for android.compileSdkVersion.
|
||||||
|
if (!project.hasProperty('cdvCompileSdkVersion')) {
|
||||||
|
cdvCompileSdkVersion = null;
|
||||||
|
}
|
||||||
|
// The value for android.buildToolsVersion.
|
||||||
|
if (!project.hasProperty('cdvBuildToolsVersion')) {
|
||||||
|
cdvBuildToolsVersion = null;
|
||||||
|
}
|
||||||
|
// Sets the versionCode to the given value.
|
||||||
|
if (!project.hasProperty('cdvVersionCode')) {
|
||||||
|
cdvVersionCode = null
|
||||||
|
}
|
||||||
|
// Sets the minSdkVersion to the given value.
|
||||||
|
if (!project.hasProperty('cdvMinSdkVersion')) {
|
||||||
|
cdvMinSdkVersion = null
|
||||||
|
}
|
||||||
|
// Whether to build architecture-specific APKs.
|
||||||
|
if (!project.hasProperty('cdvBuildMultipleApks')) {
|
||||||
|
cdvBuildMultipleApks = null
|
||||||
|
}
|
||||||
|
// .properties files to use for release signing.
|
||||||
|
if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
|
||||||
|
cdvReleaseSigningPropertiesFile = null
|
||||||
|
}
|
||||||
|
// .properties files to use for debug signing.
|
||||||
|
if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
|
||||||
|
cdvDebugSigningPropertiesFile = null
|
||||||
|
}
|
||||||
|
// Set by build.js script.
|
||||||
|
if (!project.hasProperty('cdvBuildArch')) {
|
||||||
|
cdvBuildArch = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin gradle extensions can append to this to have code run at the end.
|
||||||
|
cdvPluginPostBuildExtras = []
|
||||||
|
}
|
||||||
|
|
||||||
|
// PLUGIN GRADLE EXTENSIONS START
|
||||||
|
// PLUGIN GRADLE EXTENSIONS END
|
||||||
|
|
||||||
|
def hasBuildExtras = file('build-extras.gradle').exists()
|
||||||
|
if (hasBuildExtras) {
|
||||||
|
apply from: 'build-extras.gradle'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set property defaults after extension .gradle files.
|
||||||
|
if (ext.cdvCompileSdkVersion == null) {
|
||||||
|
ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
|
||||||
|
}
|
||||||
|
if (ext.cdvBuildToolsVersion == null) {
|
||||||
|
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
|
||||||
|
}
|
||||||
|
if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
|
||||||
|
ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
|
||||||
|
}
|
||||||
|
if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
|
||||||
|
ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cast to appropriate types.
|
||||||
|
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
|
||||||
|
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
|
||||||
|
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
|
||||||
|
|
||||||
|
def computeBuildTargetName(debugBuild) {
|
||||||
|
def ret = 'assemble'
|
||||||
|
if (cdvBuildMultipleApks && cdvBuildArch) {
|
||||||
|
def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
|
||||||
|
ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
|
||||||
|
}
|
||||||
|
return ret + (debugBuild ? 'Debug' : 'Release')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make cdvBuild a task that depends on the debug/arch-sepecific task.
|
||||||
|
task cdvBuildDebug
|
||||||
|
cdvBuildDebug.dependsOn {
|
||||||
|
return computeBuildTargetName(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
task cdvBuildRelease
|
||||||
|
cdvBuildRelease.dependsOn {
|
||||||
|
return computeBuildTargetName(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
task cdvPrintProps << {
|
||||||
|
println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
|
||||||
|
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
|
||||||
|
println('cdvVersionCode=' + cdvVersionCode)
|
||||||
|
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
|
||||||
|
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
|
||||||
|
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
|
||||||
|
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
|
||||||
|
println('cdvBuildArch=' + cdvBuildArch)
|
||||||
|
println('computedVersionCode=' + android.defaultConfig.versionCode)
|
||||||
|
android.productFlavors.each { flavor ->
|
||||||
|
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
manifest.srcFile 'AndroidManifest.xml'
|
||||||
|
java.srcDirs = ['src']
|
||||||
|
resources.srcDirs = ['src']
|
||||||
|
aidl.srcDirs = ['src']
|
||||||
|
renderscript.srcDirs = ['src']
|
||||||
|
res.srcDirs = ['res']
|
||||||
|
assets.srcDirs = ['assets']
|
||||||
|
jniLibs.srcDirs = ['libs']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
|
||||||
|
applicationId privateHelpers.extractStringFromManifest("package")
|
||||||
|
|
||||||
|
if (cdvMinSdkVersion != null) {
|
||||||
|
minSdkVersion cdvMinSdkVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lintOptions {
|
||||||
|
abortOnError false;
|
||||||
|
}
|
||||||
|
|
||||||
|
compileSdkVersion cdvCompileSdkVersion
|
||||||
|
buildToolsVersion cdvBuildToolsVersion
|
||||||
|
|
||||||
|
if (Boolean.valueOf(cdvBuildMultipleApks)) {
|
||||||
|
productFlavors {
|
||||||
|
armv7 {
|
||||||
|
versionCode defaultConfig.versionCode*10 + 2
|
||||||
|
ndk {
|
||||||
|
abiFilters "armeabi-v7a", ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x86 {
|
||||||
|
versionCode defaultConfig.versionCode*10 + 4
|
||||||
|
ndk {
|
||||||
|
abiFilters "x86", ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
all {
|
||||||
|
ndk {
|
||||||
|
abiFilters "all", ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
ELSE NOTHING! DON'T MESS WITH THE VERSION CODE IF YOU DON'T HAVE TO!
|
||||||
|
|
||||||
|
else if (!cdvVersionCode) {
|
||||||
|
def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
|
||||||
|
// Vary versionCode by the two most common API levels:
|
||||||
|
// 14 is ICS, which is the lowest API level for many apps.
|
||||||
|
// 20 is Lollipop, which is the lowest API level for the updatable system webview.
|
||||||
|
if (minSdkVersion >= 20) {
|
||||||
|
defaultConfig.versionCode += 9
|
||||||
|
} else if (minSdkVersion >= 14) {
|
||||||
|
defaultConfig.versionCode += 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_6
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_6
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cdvReleaseSigningPropertiesFile) {
|
||||||
|
signingConfigs {
|
||||||
|
release {
|
||||||
|
// These must be set or Gradle will complain (even if they are overridden).
|
||||||
|
keyAlias = ""
|
||||||
|
keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
|
||||||
|
storeFile = null
|
||||||
|
storePassword = "__unset"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
signingConfig signingConfigs.release
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
|
||||||
|
}
|
||||||
|
if (cdvDebugSigningPropertiesFile) {
|
||||||
|
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile fileTree(dir: 'libs', include: '*.jar')
|
||||||
|
// SUB-PROJECT DEPENDENCIES START
|
||||||
|
// SUB-PROJECT DEPENDENCIES END
|
||||||
|
}
|
||||||
|
|
||||||
|
def promptForReleaseKeyPassword() {
|
||||||
|
if (!cdvReleaseSigningPropertiesFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
|
||||||
|
android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
|
||||||
|
}
|
||||||
|
if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
|
||||||
|
android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle.taskGraph.whenReady { taskGraph ->
|
||||||
|
taskGraph.getAllTasks().each() { task ->
|
||||||
|
if (task.name == 'validateReleaseSigning' || task.name == 'validateSigningRelease') {
|
||||||
|
promptForReleaseKeyPassword()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def addSigningProps(propsFilePath, signingConfig) {
|
||||||
|
def propsFile = file(propsFilePath)
|
||||||
|
def props = new Properties()
|
||||||
|
propsFile.withReader { reader ->
|
||||||
|
props.load(reader)
|
||||||
|
}
|
||||||
|
|
||||||
|
def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
|
||||||
|
if (!storeFile.isAbsolute()) {
|
||||||
|
storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
|
||||||
|
}
|
||||||
|
if (!storeFile.exists()) {
|
||||||
|
throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
|
||||||
|
}
|
||||||
|
signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
|
||||||
|
signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
|
||||||
|
signingConfig.storeFile = storeFile
|
||||||
|
signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
|
||||||
|
def storeType = props.get('storeType', props.get('key.store.type', ''))
|
||||||
|
if (!storeType) {
|
||||||
|
def filename = storeFile.getName().toLowerCase();
|
||||||
|
if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
|
||||||
|
storeType = 'pkcs12'
|
||||||
|
} else {
|
||||||
|
storeType = signingConfig.storeType // "jks"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signingConfig.storeType = storeType
|
||||||
|
}
|
||||||
|
|
||||||
|
for (def func : cdvPluginPostBuildExtras) {
|
||||||
|
func()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This can be defined within build-extras.gradle as:
|
||||||
|
// ext.postBuildExtras = { ... code here ... }
|
||||||
|
if (hasProperty('postBuildExtras')) {
|
||||||
|
postBuildExtras()
|
||||||
|
}
|
BIN
bin/templates/project/res/drawable-land-hdpi/screen.png
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
bin/templates/project/res/drawable-land-ldpi/screen.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
bin/templates/project/res/drawable-land-mdpi/screen.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
bin/templates/project/res/drawable-land-xhdpi/screen.png
Normal file
After Width: | Height: | Size: 139 KiB |
BIN
bin/templates/project/res/drawable-land-xxhdpi/screen.png
Normal file
After Width: | Height: | Size: 222 KiB |
BIN
bin/templates/project/res/drawable-land-xxxhdpi/screen.png
Normal file
After Width: | Height: | Size: 286 KiB |
BIN
bin/templates/project/res/drawable-port-hdpi/screen.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
bin/templates/project/res/drawable-port-ldpi/screen.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
bin/templates/project/res/drawable-port-mdpi/screen.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
bin/templates/project/res/drawable-port-xhdpi/screen.png
Normal file
After Width: | Height: | Size: 138 KiB |
BIN
bin/templates/project/res/drawable-port-xxhdpi/screen.png
Normal file
After Width: | Height: | Size: 207 KiB |
BIN
bin/templates/project/res/drawable-port-xxxhdpi/screen.png
Normal file
After Width: | Height: | Size: 292 KiB |
BIN
bin/templates/project/res/mipmap-hdpi/icon.png
Normal file
After Width: | Height: | Size: 3.3 KiB |