Compare commits
237 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cdcb4ddcd9 | |||
| 8e53e2aa56 | |||
| 5276f56cc4 | |||
| 9df6793f34 | |||
| d90e191837 | |||
| d5d448888d | |||
| 8d8600b442 | |||
| 0bf6455153 | |||
| 80b7a7f6ac | |||
| 6b789c57e8 | |||
| b8a344fc17 | |||
| 1b6319e9cf | |||
| 2cc81253ff | |||
| 499c694146 | |||
| bc32cca281 | |||
| dead4b4ab6 | |||
| 305cb2cdd5 | |||
| 287bfcbaa3 | |||
| 2a61b751ab | |||
| a830145f36 | |||
| 08dc1dd9b9 | |||
| e86b211cd1 | |||
| 6c5febc189 | |||
| 4d0d60c294 | |||
| 16a88ec631 | |||
| 1ce2b6b315 | |||
| 43a6805902 | |||
| 566262c923 | |||
| e4bff281b2 | |||
| 9a675912f8 | |||
| f86044e6ce | |||
| 43fdaa91a3 | |||
| 80f46aefcd | |||
| 71f63d7b33 | |||
| 8d47cd73c0 | |||
| 6d451bc6f9 | |||
| 6402e7b755 | |||
| c93f93f637 | |||
| 6e51943d15 | |||
| c81cd871f8 | |||
| 8ab1dbc373 | |||
| fb26050fab | |||
| c56cd4d5a8 | |||
| de105e8651 | |||
| 8e98de6e7c | |||
| 6372ca3fac | |||
| 3712619f5c | |||
| dee1e77d0b | |||
| d01ed80a61 | |||
| 92268b2e76 | |||
| 0924654a47 | |||
| 8ef742e79d | |||
| 64ef13c6e0 | |||
| 66ad2c948e | |||
| 60e022fedd | |||
| 09256b766f | |||
| a951793431 | |||
| f4b8f44d4a | |||
| 08ab7d4b59 | |||
| 5889001465 | |||
| 91d2716122 | |||
| 0e6ad28e56 | |||
| fd57909730 | |||
| e3cc75caff | |||
| e26142f43b | |||
| d0f972e128 | |||
| e42fedc820 | |||
| f0c9814c04 | |||
| 529278190c | |||
| fcaab36484 | |||
| 5dfa995a4b | |||
| c35a990c09 | |||
| 11f40bd2cc | |||
| 7e8b47d012 | |||
| 902aa32dda | |||
| 42c0cba7f7 | |||
| f2b84d8d83 | |||
| 1b11206174 | |||
| c93e3e9f6f | |||
| 9808a0d4d3 | |||
| bd1697dbd2 | |||
| b3b8690bbd | |||
| ad742ec93c | |||
| 1de7c38134 | |||
| 997943a194 | |||
| 47c6048d53 | |||
| a64d459c8e | |||
| a5ad440f17 | |||
| acad24d62a | |||
| 989b4cc913 | |||
| 38c6627999 | |||
| 4b9e18c6b8 | |||
| 906f8cc002 | |||
| 01ab11644c | |||
| 4cf3dcfaae | |||
| b177f84825 | |||
| 485e6e0e4d | |||
| 516c3411aa | |||
| 908354e7fa | |||
| 9531dbbc7b | |||
| d10dd1c0b4 | |||
| 6533474070 | |||
| 576edb53bb | |||
| 20e390af85 | |||
| 931251a5a8 | |||
| 9697550488 | |||
| 3dac984613 | |||
| 867da56e2e | |||
| 719acd3ab1 | |||
| 549cae0a06 | |||
| bb45f4f3ba | |||
| b4de6f55c4 | |||
| e99c145d55 | |||
| 9cb9f32fbb | |||
| a6f30b6977 | |||
| 73692e60d8 | |||
| 4abe3d3a49 | |||
| 54df4a116c | |||
| 715ce2f9ac | |||
| 7a98708eef | |||
| d9c08f12a7 | |||
| e41fbc5708 | |||
| 634f92efb6 | |||
| 98a7b759e8 | |||
| 3976685e4e | |||
| f7688bc64e | |||
| 18e28294d6 | |||
| 39bd0d6463 | |||
| c1819cc027 | |||
| f228d90ca2 | |||
| 5f44af3757 | |||
| 8a4ae311ce | |||
| ef2434188e | |||
| a014228f7c | |||
| 2163c8ae05 | |||
| 47bb5184a0 | |||
| f1f1ac3cbd | |||
| f1396c7aad | |||
| 21ae48eada | |||
| 53e1c1b65c | |||
| 858611f95e | |||
| 5c334b6c10 | |||
| cf5a02ea0f | |||
| a67bc75b93 | |||
| 895ab0c970 | |||
| 21f84732c8 | |||
| 7eed65e9b4 | |||
| cf5915ad01 | |||
| a4caa87d29 | |||
| bbb3913a36 | |||
| 92f07d0418 | |||
| 578a642209 | |||
| 9d03e4ec0a | |||
| 576ad183e7 | |||
| e31596f60e | |||
| ef493b4c0f | |||
| c15312ee70 | |||
| 3caefcae49 | |||
| c2f6631f91 | |||
| fb1dfb27df | |||
| 898a6a8d8d | |||
| 7da53741cd | |||
| 47aabc631d | |||
| fb75ac371d | |||
| 98c866704a | |||
| e58453d3e6 | |||
| 03c62e1ce2 | |||
| 2c10545cd8 | |||
| ff2ec7eed1 | |||
| 8dfddef6f9 | |||
| 73edf4de7b | |||
| cfa58a5661 | |||
| 905bff3d59 | |||
| eadcd33e84 | |||
| 76fe89dd1f | |||
| 3f487c5c28 | |||
| c35a46ec45 | |||
| e3eb933182 | |||
| dacb0e5c72 | |||
| 23b24491c3 | |||
| 7ab0cf123d | |||
| 8f2a4c7231 | |||
| ce53154555 | |||
| c0188ab95a | |||
| ebbd91f87d | |||
| 4b0725dfc2 | |||
| 350d35fb24 | |||
| 8ee3a73dd1 | |||
| b6e4598e7c | |||
| bd2ad99402 | |||
| d26c1199ab | |||
| 1ea7c1366a | |||
| b2263fe35e | |||
| bd07907a4c | |||
| ca8931c8af | |||
| 46a036ef26 | |||
| e9750b5cab | |||
| 0bf0e48698 | |||
| 4f1aa97ea9 | |||
| f90f004dea | |||
| 559b0833b4 | |||
| 31bad290d5 | |||
| 2e88f7ead2 | |||
| 1a8154c90e | |||
| 8fb49ec7ec | |||
| 393dad6349 | |||
| 2c3db19310 | |||
| 472ab626d6 | |||
| 2106e2e081 | |||
| d3c80ea5d5 | |||
| 6dad25668c | |||
| d862d42e76 | |||
| 828b5f053a | |||
| 032d1fa9cb | |||
| 83ad646734 | |||
| 88c25a6a6a | |||
| a254cfc841 | |||
| 0d4b9f4ba6 | |||
| bf29fe0e10 | |||
| 3df8f8b120 | |||
| 38d0e684f1 | |||
| 83e9aefff5 | |||
| 02ee925103 | |||
| fc69da7a42 | |||
| 5dc179ebef | |||
| 59e3b907e9 | |||
| fe7629e8fc | |||
| 76180d3ea1 | |||
| 5c4f8ca246 | |||
| b8530a6b70 | |||
| 83686542b2 | |||
| b1551cad98 | |||
| 5af6b016c1 | |||
| 6abd6d6b47 | |||
| e456a325f9 | |||
| eddad666ff | |||
| ca9a25e860 |
@@ -0,0 +1,22 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
commits: commits@cordova.apache.org
|
||||||
|
issues: issues@cordova.apache.org
|
||||||
|
pullrequests_status: issues@cordova.apache.org
|
||||||
|
pullrequests_comment: issues@cordova.apache.org
|
||||||
@@ -1 +1,3 @@
|
|||||||
bin/templates/project/assets/www/cordova.js
|
bin/templates/project/assets/www/cordova.js
|
||||||
|
test/android/app
|
||||||
|
test/androidx/app
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
root: true
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
extends: semistandard
|
# or more contributor license agreements. See the NOTICE file
|
||||||
rules:
|
# distributed with this work for additional information
|
||||||
indent:
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
- error
|
# to you under the Apache License, Version 2.0 (the
|
||||||
- 4
|
# "License"); you may not use this file except in compliance
|
||||||
camelcase: off
|
# with the License. You may obtain a copy of the License at
|
||||||
padded-blocks: off
|
#
|
||||||
operator-linebreak: off
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
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'
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!--
|
||||||
|
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
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
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
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
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?
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
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)
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Please make sure the checklist boxes are all checked before submitting the PR. The checklist
|
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:
|
||||||
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
|
||||||
|
|
||||||
@@ -10,13 +9,27 @@ 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
|
|
||||||
- [ ] 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've run the tests to see all new and existing tests pass
|
||||||
- [ ] Added automated test coverage as appropriate for this change.
|
- [ ] I 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
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# 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: [10.x, 12.x]
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
|
||||||
|
- name: set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
|
||||||
|
- name: Environment Information
|
||||||
|
run: |
|
||||||
|
node --version
|
||||||
|
npm --version
|
||||||
|
gradle --version
|
||||||
|
|
||||||
|
- name: npm install and test
|
||||||
|
run: |
|
||||||
|
npm i
|
||||||
|
npm t
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
- uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
fail_ci_if_error: true
|
||||||
@@ -26,10 +26,14 @@ example
|
|||||||
/framework/javadoc-public
|
/framework/javadoc-public
|
||||||
/framework/javadoc-private
|
/framework/javadoc-private
|
||||||
/test/.externalNativeBuild
|
/test/.externalNativeBuild
|
||||||
/test/build.gradle
|
|
||||||
/test/gradle
|
/test/android/gradle
|
||||||
/test/gradlew
|
/test/android/gradlew
|
||||||
/test/gradlew.bat
|
/test/android/gradlew.bat
|
||||||
|
/test/androidx/gradle
|
||||||
|
/test/androidx/gradlew
|
||||||
|
/test/androidx/gradlew.bat
|
||||||
|
|
||||||
/test/assets/www/.tmp*
|
/test/assets/www/.tmp*
|
||||||
/test/assets/www/cordova.js
|
/test/assets/www/cordova.js
|
||||||
/test/bin
|
/test/bin
|
||||||
@@ -43,93 +47,10 @@ tmp/**/*
|
|||||||
**/.idea/**/*
|
**/.idea/**/*
|
||||||
*.iml
|
*.iml
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
node_modules/jshint
|
node_modules/
|
||||||
node_modules/promise-matchers
|
coverage/
|
||||||
node_modules/jasmine
|
.nyc_output/
|
||||||
node_modules/rewire
|
# Eclipse Buildship files
|
||||||
node_modules/istanbul
|
.project
|
||||||
node_modules/.bin/cake
|
.settings
|
||||||
node_modules/.bin/coffee
|
.classpath
|
||||||
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/
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.*
|
||||||
|
coverage
|
||||||
|
test
|
||||||
|
spec
|
||||||
|
framework/build
|
||||||
@@ -3,7 +3,6 @@ bin
|
|||||||
gen
|
gen
|
||||||
proguard-project.txt
|
proguard-project.txt
|
||||||
spec
|
spec
|
||||||
appveyor.yml
|
|
||||||
framework/build
|
framework/build
|
||||||
ic_launcher.png
|
ic_launcher.png
|
||||||
build
|
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 = 'http://reviews.apache.org'
|
REVIEWBOARD_URL = 'https://reviews.apache.org'
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -25,13 +25,12 @@ Anyone can contribute to Cordova. And we need your contributions.
|
|||||||
|
|
||||||
There are multiple ways to contribute: report bugs, improve the docs, and
|
There are multiple ways to contribute: report bugs, improve the docs, and
|
||||||
contribute code.
|
contribute code.
|
||||||
|
|
||||||
For instructions on this, start with the
|
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:
|
||||||
- Sign and submit an Apache ICLA (Contributor License Agreement).
|
- Check for Github issues that corresponds to your contribution and link or create them if necessary.
|
||||||
- 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!
|
||||||
|
|||||||
@@ -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 Apache Cordova
|
Copyright 2015-2020 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.
|
||||||
@@ -207,7 +207,7 @@
|
|||||||
bin/node_modules/q
|
bin/node_modules/q
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
Copyright 2009–2012 Kristopher Michael Kowal. All rights reserved.
|
Copyright 2009–2017 Kristopher Michael Kowal. All rights reserved.
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to
|
of this software and associated documentation files (the "Software"), to
|
||||||
deal in the Software without restriction, including without limitation the
|
deal in the Software without restriction, including without limitation the
|
||||||
@@ -226,89 +226,42 @@ 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
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
IN THE SOFTWARE.
|
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
|
bin/node_modules/nopt
|
||||||
================================================================================
|
================================================================================
|
||||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
The ISC License
|
||||||
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
|
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
copyright notice and this permission notice appear in all copies.
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||||
|
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
bin/node_modules/which
|
bin/node_modules/which
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
The ISC License
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||||
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.
|
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||||
|
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
Apache Cordova
|
Apache Cordova
|
||||||
Copyright 2015 The Apache Software Foundation
|
Copyright 2015-2020 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).
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,26 +19,21 @@
|
|||||||
#
|
#
|
||||||
-->
|
-->
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/Humbedooh/cordova-android)
|
|
||||||
[](https://travis-ci.org/apache/cordova-android)
|
|
||||||
[](https://codecov.io/github/apache/cordova-android?branch=master)
|
|
||||||
|
|
||||||
# Cordova Android
|
# Cordova Android
|
||||||
|
|
||||||
Cordova Android is an Android application library that allows for Cordova-based
|
[](https://nodei.co/npm/cordova-android/)
|
||||||
projects to be built for the Android Platform. Cordova based applications are,
|
|
||||||
at the core, applications written with web technology: HTML, CSS and JavaScript.
|
[](https://github.com/apache/cordova-android/actions?query=branch%3Amaster)
|
||||||
|
[](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.
|
||||||
|
|
||||||
[Apache Cordova](https://cordova.apache.org) is a project of The Apache Software Foundation (ASF).
|
[Apache Cordova](https://cordova.apache.org) is a project of The Apache Software Foundation (ASF).
|
||||||
|
|
||||||
: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)
|
|
||||||
|
|
||||||
|
|
||||||
## Requires
|
## Requires
|
||||||
|
|
||||||
- Java JDK 1.8 or greater
|
- Java JDK 1.8
|
||||||
- Android SDK [http://developer.android.com](http://developer.android.com)
|
- Android SDK [http://developer.android.com](https://developer.android.com/)
|
||||||
|
|
||||||
|
|
||||||
## Cordova Android Developer Tools
|
## Cordova Android Developer Tools
|
||||||
|
|
||||||
@@ -65,6 +60,4 @@ These commands live in a generated Cordova Android project. Any interactions wit
|
|||||||
|
|
||||||
## Running the Native Tests
|
## Running the Native Tests
|
||||||
|
|
||||||
The `test/` directory in this project contains an Android test project that can
|
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!
|
||||||
be used to run different kinds of native tests. Check out the
|
|
||||||
[README contained therein](test/README.md) for more details!
|
|
||||||
|
|||||||
@@ -18,7 +18,157 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
-->
|
-->
|
||||||
## Release Notes for Cordova (Android) ##
|
## Release Notes for Cordova (Android)
|
||||||
|
|
||||||
|
### 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.0 (Feb 20, 2018)
|
### 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-13879](https://issues.apache.org/jira/browse/CB-13879) updated gradle tools dependency to 3.0.1 for project template
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -21,9 +21,7 @@
|
|||||||
|
|
||||||
var android_sdk = require('./templates/cordova/lib/android_sdk');
|
var android_sdk = require('./templates/cordova/lib/android_sdk');
|
||||||
|
|
||||||
android_sdk.print_newest_available_sdk_target().done(null, function(err) {
|
android_sdk.print_newest_available_sdk_target().catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -21,10 +21,11 @@
|
|||||||
|
|
||||||
var check_reqs = require('./templates/cordova/lib/check_reqs');
|
var check_reqs = require('./templates/cordova/lib/check_reqs');
|
||||||
|
|
||||||
check_reqs.run().done(
|
check_reqs.run().then(
|
||||||
function success() {
|
function success () {
|
||||||
console.log('Looks like your environment fully supports cordova-android development!');
|
console.log('Looks like your environment fully supports cordova-android development!');
|
||||||
}, function fail(err) {
|
},
|
||||||
|
function fail (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
if (fs.existsSync('./test/gradlew')) {
|
||||||
|
fs.unlinkSync('./test/gradlew');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync('./test/gradlew.bat')) {
|
||||||
|
fs.unlinkSync('./test/gradlew.bat');
|
||||||
|
}
|
||||||
@@ -23,12 +23,12 @@ var ConfigParser = require('cordova-common').ConfigParser;
|
|||||||
var Api = require('./templates/cordova/Api');
|
var Api = require('./templates/cordova/Api');
|
||||||
|
|
||||||
var argv = require('nopt')({
|
var argv = require('nopt')({
|
||||||
'help' : Boolean,
|
help: Boolean,
|
||||||
'cli' : Boolean,
|
cli: Boolean,
|
||||||
'shared' : Boolean,
|
shared: Boolean,
|
||||||
'link' : Boolean,
|
link: Boolean,
|
||||||
'activity-name' : [String, undefined]
|
'activity-name': [String, undefined]
|
||||||
}, { 'd' : '--verbose' });
|
}, { d: '--verbose' });
|
||||||
|
|
||||||
if (argv.help || argv.argv.remain.length === 0) {
|
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('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' <path_to_new_project> <package_name> <project_name> [<template_path>] [--activity-name <activity_name>] [--link]');
|
||||||
@@ -55,4 +55,7 @@ var options = {
|
|||||||
|
|
||||||
require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv);
|
require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv);
|
||||||
|
|
||||||
Api.createPlatform(argv.argv.remain[0], config, options).done();
|
Api.createPlatform(argv.argv.remain[0], config, options).catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
process.exitCode = 1;
|
||||||
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
@@ -23,4 +23,4 @@ IF EXIST %script_path% (
|
|||||||
ECHO.
|
ECHO.
|
||||||
ECHO ERROR: Could not find 'create' script in 'bin' folder, aborting...>&2
|
ECHO ERROR: Could not find 'create' script in 'bin' folder, aborting...>&2
|
||||||
EXIT /B 1
|
EXIT /B 1
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,10 +17,9 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var shell = require('shelljs');
|
|
||||||
var Q = require('q');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
var fs = require('fs-extra');
|
||||||
|
var utils = require('../../bin/lib/utils');
|
||||||
var check_reqs = require('./../templates/cordova/lib/check_reqs');
|
var check_reqs = require('./../templates/cordova/lib/check_reqs');
|
||||||
var ROOT = path.join(__dirname, '..', '..');
|
var ROOT = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
@@ -34,20 +31,12 @@ var AndroidManifest = require('../templates/cordova/lib/AndroidManifest');
|
|||||||
// (since we can then mock and control behaviour of all of these functions)
|
// (since we can then mock and control behaviour of all of these functions)
|
||||||
exports.validatePackageName = validatePackageName;
|
exports.validatePackageName = validatePackageName;
|
||||||
exports.validateProjectName = validateProjectName;
|
exports.validateProjectName = validateProjectName;
|
||||||
exports.setShellFatal = setShellFatal;
|
|
||||||
exports.copyJsAndLibrary = copyJsAndLibrary;
|
exports.copyJsAndLibrary = copyJsAndLibrary;
|
||||||
exports.copyScripts = copyScripts;
|
exports.copyScripts = copyScripts;
|
||||||
exports.copyBuildRules = copyBuildRules;
|
exports.copyBuildRules = copyBuildRules;
|
||||||
exports.writeProjectProperties = writeProjectProperties;
|
exports.writeProjectProperties = writeProjectProperties;
|
||||||
exports.prepBuildFiles = prepBuildFiles;
|
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) {
|
function getFrameworkDir (projectPath, shared) {
|
||||||
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
||||||
}
|
}
|
||||||
@@ -56,53 +45,33 @@ function copyJsAndLibrary (projectPath, shared, projectName, isLegacy) {
|
|||||||
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
|
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
|
||||||
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
|
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
|
||||||
var app_path = path.join(projectPath, 'app', 'src', 'main');
|
var app_path = path.join(projectPath, 'app', 'src', 'main');
|
||||||
|
const platform_www = path.join(projectPath, 'platform_www');
|
||||||
|
|
||||||
if (isLegacy) {
|
if (isLegacy) {
|
||||||
app_path = projectPath;
|
app_path = projectPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.cp('-f', srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
fs.copySync(srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
||||||
|
|
||||||
// Copy the cordova.js file to platforms/<platform>/platform_www/
|
// 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
|
// The www dir is nuked on each prepare so we keep cordova.js in platform_www
|
||||||
shell.mkdir('-p', path.join(projectPath, 'platform_www'));
|
fs.ensureDirSync(platform_www);
|
||||||
shell.cp('-f', srcCordovaJsPath, path.join(projectPath, 'platform_www'));
|
fs.copySync(srcCordovaJsPath, path.join(platform_www, 'cordova.js'));
|
||||||
|
|
||||||
// Copy cordova-js-src directory into platform_www directory.
|
// Copy cordova-js-src directory into platform_www directory.
|
||||||
// We need these files to build cordova.js if using browserify method.
|
// 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'));
|
fs.copySync(path.join(ROOT, 'cordova-js-src'), path.join(platform_www, 'cordova-js-src'));
|
||||||
|
|
||||||
// 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) {
|
if (shared) {
|
||||||
var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true));
|
var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true));
|
||||||
fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
|
fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
|
||||||
} else {
|
} else {
|
||||||
shell.mkdir('-p', nestedCordovaLibPath);
|
fs.ensureDirSync(nestedCordovaLibPath);
|
||||||
shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
|
fs.copySync(path.join(ROOT, 'framework', 'AndroidManifest.xml'), path.join(nestedCordovaLibPath, 'AndroidManifest.xml'));
|
||||||
shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
|
fs.copySync(path.join(ROOT, 'framework', 'project.properties'), path.join(nestedCordovaLibPath, 'project.properties'));
|
||||||
shell.cp('-f', path.join(ROOT, 'framework', 'build.gradle'), nestedCordovaLibPath);
|
fs.copySync(path.join(ROOT, 'framework', 'build.gradle'), path.join(nestedCordovaLibPath, 'build.gradle'));
|
||||||
shell.cp('-f', path.join(ROOT, 'framework', 'cordova.gradle'), nestedCordovaLibPath);
|
fs.copySync(path.join(ROOT, 'framework', 'cordova.gradle'), path.join(nestedCordovaLibPath, 'cordova.gradle'));
|
||||||
shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath);
|
fs.copySync(path.join(ROOT, 'framework', 'src'), path.join(nestedCordovaLibPath, 'src'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,9 +110,9 @@ function writeProjectProperties (projectPath, target_api) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This makes no sense, what if you're building with a different build system?
|
// This makes no sense, what if you're building with a different build system?
|
||||||
function prepBuildFiles (projectPath, builder) {
|
function prepBuildFiles (projectPath) {
|
||||||
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders'));
|
var buildModule = require('../templates/cordova/lib/builders/builders');
|
||||||
buildModule.getBuilder(builder).prepBuildFiles();
|
buildModule.getBuilder(projectPath).prepBuildFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyBuildRules (projectPath, isLegacy) {
|
function copyBuildRules (projectPath, isLegacy) {
|
||||||
@@ -151,12 +120,12 @@ function copyBuildRules (projectPath, isLegacy) {
|
|||||||
|
|
||||||
if (isLegacy) {
|
if (isLegacy) {
|
||||||
// The project's build.gradle is identical to the earlier build.gradle, so it should still work
|
// 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);
|
fs.copySync(path.join(srcDir, 'legacy', 'build.gradle'), path.join(projectPath, 'legacy', 'build.gradle'));
|
||||||
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
fs.copySync(path.join(srcDir, 'wrapper.gradle'), path.join(projectPath, 'wrapper.gradle'));
|
||||||
} else {
|
} else {
|
||||||
shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath);
|
fs.copySync(path.join(srcDir, 'build.gradle'), path.join(projectPath, 'build.gradle'));
|
||||||
shell.cp('-f', path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app'));
|
fs.copySync(path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app', 'build.gradle'));
|
||||||
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
fs.copySync(path.join(srcDir, 'wrapper.gradle'), path.join(projectPath, 'wrapper.gradle'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,21 +134,29 @@ function copyScripts (projectPath) {
|
|||||||
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
|
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
|
||||||
var destScriptsDir = path.join(projectPath, 'cordova');
|
var destScriptsDir = path.join(projectPath, 'cordova');
|
||||||
// Delete old scripts directory if this is an update.
|
// Delete old scripts directory if this is an update.
|
||||||
shell.rm('-rf', destScriptsDir);
|
fs.removeSync(destScriptsDir);
|
||||||
// Copy in the new ones.
|
// Copy in the new ones.
|
||||||
shell.cp('-r', srcScriptsDir, projectPath);
|
fs.copySync(srcScriptsDir, destScriptsDir);
|
||||||
shell.cp('-r', path.join(ROOT, 'node_modules'), destScriptsDir);
|
|
||||||
shell.cp(path.join(bin, 'check_reqs*'), destScriptsDir);
|
const nodeModulesDir = path.join(ROOT, 'node_modules');
|
||||||
shell.cp(path.join(bin, 'android_sdk_version*'), destScriptsDir);
|
if (fs.existsSync(nodeModulesDir)) fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules'));
|
||||||
|
|
||||||
|
fs.copySync(path.join(bin, 'check_reqs'), path.join(destScriptsDir, 'check_reqs'));
|
||||||
|
fs.copySync(path.join(bin, 'check_reqs.bat'), path.join(destScriptsDir, 'check_reqs.bat'));
|
||||||
|
fs.copySync(path.join(bin, 'android_sdk_version'), path.join(destScriptsDir, 'android_sdk_version'));
|
||||||
|
fs.copySync(path.join(bin, 'android_sdk_version.bat'), path.join(destScriptsDir, 'android_sdk_version.bat'));
|
||||||
|
|
||||||
var check_reqs = path.join(destScriptsDir, 'check_reqs');
|
var check_reqs = path.join(destScriptsDir, 'check_reqs');
|
||||||
var android_sdk_version = path.join(destScriptsDir, 'android_sdk_version');
|
var android_sdk_version = path.join(destScriptsDir, 'android_sdk_version');
|
||||||
|
|
||||||
// TODO: the two files being edited on-the-fly here are shared between
|
// TODO: the two files being edited on-the-fly here are shared between
|
||||||
// platform and project-level commands. the below `sed` is updating the
|
// platform and project-level commands. the below is updating the
|
||||||
// `require` path for the two libraries. if there's a better way to share
|
// `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
|
// modules across both the repo and generated projects, we should make sure
|
||||||
// to remove/update this.
|
// to remove/update this.
|
||||||
shell.sed('-i', /templates\/cordova\//, '', android_sdk_version);
|
const templatesCordovaRegex = /templates\/cordova\//;
|
||||||
shell.sed('-i', /templates\/cordova\//, '', check_reqs);
|
utils.replaceFileContents(android_sdk_version, templatesCordovaRegex, '');
|
||||||
|
utils.replaceFileContents(check_reqs, templatesCordovaRegex, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,19 +171,19 @@ function validatePackageName (package_name) {
|
|||||||
var msg = 'Error validating package name. ';
|
var msg = 'Error validating package name. ';
|
||||||
|
|
||||||
if (!/^[a-zA-Z][a-zA-Z0-9_]+(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.test(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'));
|
return Promise.reject(new CordovaError(msg + 'Must look like: `com.company.Name`. Currently is: `' + package_name + '`'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class is a reserved word
|
// Class is a reserved word
|
||||||
if (/\b[Cc]lass\b/.test(package_name)) {
|
if (/\b[Cc]lass\b/.test(package_name)) {
|
||||||
return Q.reject(new CordovaError(msg + '"class" is a reserved word'));
|
return Promise.reject(new CordovaError(msg + '"class" is a reserved word'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Q.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether a project name is acceptable for use as an android class.
|
* Test whether given string is acceptable for use as a project name
|
||||||
* Returns a promise, fulfilled if the project name is acceptable; rejected
|
* Returns a promise, fulfilled if the project name is acceptable; rejected
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -214,20 +191,10 @@ function validateProjectName (project_name) {
|
|||||||
var msg = 'Error validating project name. ';
|
var msg = 'Error validating project name. ';
|
||||||
// Make sure there's something there
|
// Make sure there's something there
|
||||||
if (project_name === '') {
|
if (project_name === '') {
|
||||||
return Q.reject(new CordovaError(msg + 'Project name cannot be empty'));
|
return Promise.reject(new CordovaError(msg + 'Project name cannot be empty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce stupid name error
|
return Promise.resolve();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,19 +216,18 @@ function validateProjectName (project_name) {
|
|||||||
* @return {Promise<String>} Directory where application has been created
|
* @return {Promise<String>} Directory where application has been created
|
||||||
*/
|
*/
|
||||||
exports.create = function (project_path, config, options, events) {
|
exports.create = function (project_path, config, options, events) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
// Set default values for path, package and name
|
// Set default values for path, package and name
|
||||||
project_path = path.relative(process.cwd(), (project_path || 'CordovaExample'));
|
project_path = path.relative(process.cwd(), (project_path || 'CordovaExample'));
|
||||||
// Check if project already exists
|
// Check if project already exists
|
||||||
if (fs.existsSync(project_path)) {
|
if (fs.existsSync(project_path)) {
|
||||||
return Q.reject(new CordovaError('Project already exists! Delete and recreate'));
|
return Promise.reject(new CordovaError('Project already exists! Delete and recreate'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
|
var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
|
||||||
var project_name = config.name() ?
|
var project_name = config.name()
|
||||||
config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
|
? config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
|
||||||
|
|
||||||
var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity';
|
var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity';
|
||||||
var target_api = check_reqs.get_target();
|
var target_api = check_reqs.get_target();
|
||||||
@@ -269,7 +235,7 @@ exports.create = function (project_path, config, options, events) {
|
|||||||
// Make the package conform to Java package types
|
// Make the package conform to Java package types
|
||||||
return exports.validatePackageName(package_name)
|
return exports.validatePackageName(package_name)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
exports.validateProjectName(project_name);
|
return exports.validateProjectName(project_name);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// Log the given values for the project
|
// Log the given values for the project
|
||||||
events.emit('log', 'Creating Cordova project for the Android platform:');
|
events.emit('log', 'Creating Cordova project for the Android platform:');
|
||||||
@@ -281,57 +247,55 @@ exports.create = function (project_path, config, options, events) {
|
|||||||
|
|
||||||
events.emit('verbose', 'Copying android template project to ' + project_path);
|
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 project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
|
var app_path = path.join(project_path, 'app', 'src', 'main');
|
||||||
var app_path = path.join(project_path, 'app', 'src', 'main');
|
|
||||||
|
|
||||||
// copy project template
|
// copy project template
|
||||||
shell.mkdir('-p', app_path);
|
fs.ensureDirSync(app_path);
|
||||||
shell.cp('-r', path.join(project_template_dir, 'assets'), app_path);
|
fs.copySync(path.join(project_template_dir, 'assets'), path.join(app_path, 'assets'));
|
||||||
shell.cp('-r', path.join(project_template_dir, 'res'), app_path);
|
fs.copySync(path.join(project_template_dir, 'res'), path.join(app_path, 'res'));
|
||||||
shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
fs.copySync(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).
|
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
||||||
shell.mkdir(path.join(app_path, 'libs'));
|
fs.ensureDirSync(path.join(app_path, 'libs'));
|
||||||
|
|
||||||
// copy cordova.js, cordova.jar
|
// copy cordova.js, cordova.jar
|
||||||
exports.copyJsAndLibrary(project_path, options.link, safe_activity_name);
|
exports.copyJsAndLibrary(project_path, options.link, safe_activity_name);
|
||||||
|
|
||||||
// Set up ther Android Studio paths
|
// Set up ther Android Studio paths
|
||||||
var java_path = path.join(app_path, 'java');
|
var java_path = path.join(app_path, 'java');
|
||||||
var assets_path = path.join(app_path, 'assets');
|
var assets_path = path.join(app_path, 'assets');
|
||||||
var resource_path = path.join(app_path, 'res');
|
var resource_path = path.join(app_path, 'res');
|
||||||
shell.mkdir('-p', java_path);
|
fs.ensureDirSync(java_path);
|
||||||
shell.mkdir('-p', assets_path);
|
fs.ensureDirSync(assets_path);
|
||||||
shell.mkdir('-p', resource_path);
|
fs.ensureDirSync(resource_path);
|
||||||
|
|
||||||
// interpolate the activity name and package
|
// interpolate the activity name and package
|
||||||
var packagePath = package_name.replace(/\./g, path.sep);
|
var packagePath = package_name.replace(/\./g, path.sep);
|
||||||
var activity_dir = path.join(java_path, packagePath);
|
var activity_dir = path.join(java_path, packagePath);
|
||||||
var activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
var activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
||||||
|
|
||||||
shell.mkdir('-p', activity_dir);
|
fs.ensureDirSync(activity_dir);
|
||||||
shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
|
fs.copySync(path.join(project_template_dir, 'Activity.java'), activity_path);
|
||||||
shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
|
utils.replaceFileContents(activity_path, /__ACTIVITY__/, safe_activity_name);
|
||||||
shell.sed('-i', /__NAME__/, project_name, path.join(app_path, 'res', 'values', 'strings.xml'));
|
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, project_name);
|
||||||
shell.sed('-i', /__ID__/, package_name, activity_path);
|
utils.replaceFileContents(activity_path, /__ID__/, package_name);
|
||||||
|
|
||||||
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
||||||
manifest.setPackageId(package_name)
|
manifest.setPackageId(package_name)
|
||||||
.setTargetSdkVersion(target_api.split('-')[1])
|
.getActivity().setName(safe_activity_name);
|
||||||
.getActivity().setName(safe_activity_name);
|
|
||||||
|
|
||||||
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
||||||
manifest.write(manifest_path);
|
manifest.write(manifest_path);
|
||||||
|
|
||||||
|
exports.copyScripts(project_path);
|
||||||
|
exports.copyBuildRules(project_path);
|
||||||
|
|
||||||
exports.copyScripts(project_path);
|
|
||||||
exports.copyBuildRules(project_path);
|
|
||||||
});
|
|
||||||
// Link it to local android install.
|
// Link it to local android install.
|
||||||
exports.writeProjectProperties(project_path, target_api);
|
exports.writeProjectProperties(project_path, target_api);
|
||||||
exports.prepBuildFiles(project_path, 'studio');
|
exports.prepBuildFiles(project_path);
|
||||||
events.emit('log', generateDoneMessage('create', options.link));
|
events.emit('log', generateDoneMessage('create', options.link));
|
||||||
}).thenResolve(project_path);
|
}).then(() => project_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
function generateDoneMessage (type, link) {
|
function generateDoneMessage (type, link) {
|
||||||
@@ -345,7 +309,6 @@ function generateDoneMessage (type, link) {
|
|||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
exports.update = function (projectPath, options, events) {
|
exports.update = function (projectPath, options, events) {
|
||||||
|
|
||||||
var errorString =
|
var errorString =
|
||||||
'An in-place platform update is not supported. \n' +
|
'An in-place platform update is not supported. \n' +
|
||||||
'The `platforms` folder is always treated as a build artifact in the CLI workflow.\n' +
|
'The `platforms` folder is always treated as a build artifact in the CLI workflow.\n' +
|
||||||
@@ -356,5 +319,5 @@ exports.update = function (projectPath, options, events) {
|
|||||||
'\tcordova platform add android\n'
|
'\tcordova platform add android\n'
|
||||||
;
|
;
|
||||||
|
|
||||||
return Q.reject(errorString);
|
return Promise.reject(errorString);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Provides a set of utility methods, which can also be spied on during unit tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO: Perhaps this should live in cordova-common?
|
||||||
|
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads, searches, and replaces the found occurences with replacementString and then writes the file back out.
|
||||||
|
* A backup is not made.
|
||||||
|
*
|
||||||
|
* @param {string} file A file path to a readable & writable file
|
||||||
|
* @param {RegExp} searchRegex The search regex
|
||||||
|
* @param {string} replacementString The string to replace the found occurences
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
exports.replaceFileContents = function (file, searchRegex, replacementString) {
|
||||||
|
// let contents;
|
||||||
|
try {
|
||||||
|
var contents = fs.readFileSync(file).toString();
|
||||||
|
} catch (ex) {
|
||||||
|
console.log('TRYING TO READ: ', file);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
contents = contents.replace(searchRegex, replacementString);
|
||||||
|
fs.writeFileSync(file, contents);
|
||||||
|
};
|
||||||
@@ -17,15 +17,24 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo update coho to update this line.
|
||||||
|
* @todo use `package.json` instead but first
|
||||||
|
* figure out how this fit in with the platform-centered workflow structure.
|
||||||
|
* This workflow would not have the `package.json` file.
|
||||||
|
*/
|
||||||
|
// Coho updates this line
|
||||||
|
const VERSION = '9.0.0';
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Q = require('q');
|
|
||||||
|
|
||||||
var AndroidProject = require('./lib/AndroidProject');
|
var AndroidProject = require('./lib/AndroidProject');
|
||||||
var AndroidStudio = require('./lib/AndroidStudio');
|
|
||||||
var PluginManager = require('cordova-common').PluginManager;
|
var PluginManager = require('cordova-common').PluginManager;
|
||||||
|
|
||||||
var CordovaLogger = require('cordova-common').CordovaLogger;
|
var CordovaLogger = require('cordova-common').CordovaLogger;
|
||||||
var selfEvents = require('cordova-common').events;
|
var selfEvents = require('cordova-common').events;
|
||||||
|
var ConfigParser = require('cordova-common').ConfigParser;
|
||||||
|
const prepare = require('./lib/prepare').prepare;
|
||||||
|
|
||||||
var PLATFORM = 'android';
|
var PLATFORM = 'android';
|
||||||
|
|
||||||
@@ -52,360 +61,324 @@ function setupEvents (externalEventEmitter) {
|
|||||||
* The PlatformApi instance also should define the following field:
|
* The PlatformApi instance also should define the following field:
|
||||||
*
|
*
|
||||||
* * platform: String that defines a platform name.
|
* * platform: String that defines a platform name.
|
||||||
|
* @class Api
|
||||||
*/
|
*/
|
||||||
function Api (platform, platformRootDir, events) {
|
class Api {
|
||||||
this.platform = PLATFORM;
|
constructor (platform, platformRootDir, events) {
|
||||||
this.root = path.resolve(__dirname, '..');
|
this.platform = PLATFORM;
|
||||||
this.builder = 'gradle';
|
this.root = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
setupEvents(events);
|
setupEvents(events);
|
||||||
|
|
||||||
var self = this;
|
const appMain = path.join(this.root, 'app', 'src', 'main');
|
||||||
|
const appRes = path.join(appMain, 'res');
|
||||||
|
|
||||||
this.locations = {
|
this.locations = {
|
||||||
root: self.root,
|
root: this.root,
|
||||||
www: path.join(self.root, 'assets/www'),
|
www: path.join(appMain, 'assets', 'www'),
|
||||||
res: path.join(self.root, 'res'),
|
res: appRes,
|
||||||
platformWww: path.join(self.root, 'platform_www'),
|
platformWww: path.join(this.root, 'platform_www'),
|
||||||
configXml: path.join(self.root, 'res/xml/config.xml'),
|
configXml: path.join(appRes, 'xml', 'config.xml'),
|
||||||
defaultConfigXml: path.join(self.root, 'cordova/defaults.xml'),
|
defaultConfigXml: path.join(this.root, 'cordova', 'defaults.xml'),
|
||||||
strings: path.join(self.root, 'res/values/strings.xml'),
|
strings: path.join(appRes, 'values', 'strings.xml'),
|
||||||
manifest: path.join(self.root, 'AndroidManifest.xml'),
|
manifest: path.join(appMain, 'AndroidManifest.xml'),
|
||||||
build: path.join(self.root, 'build'),
|
build: path.join(this.root, 'build'),
|
||||||
javaSrc: path.join(self.root, 'src'),
|
javaSrc: path.join(appMain, 'java')
|
||||||
// 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;
|
* 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.
|
||||||
|
*/
|
||||||
|
getPlatformInfo () {
|
||||||
|
var result = {};
|
||||||
|
result.locations = this.locations;
|
||||||
|
result.root = this.root;
|
||||||
|
result.name = this.platform;
|
||||||
|
result.version = Api.version();
|
||||||
|
result.projectConfig = this._config;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Q().then(function () {
|
/**
|
||||||
// CB-11964: Do a clean when installing the plugin code to get around
|
* Updates installed platform with provided www assets and new app
|
||||||
// the Gradle bug introduced by the Android Gradle Plugin Version 2.2
|
* configuration. This method is required for CLI workflow and will be called
|
||||||
// TODO: Delete when the next version of Android Gradle plugin comes out
|
* each time before build, so the changes, made to app configuration and www
|
||||||
// Since clean doesn't just clean the build, it also wipes out www, we need
|
* code, will be applied to platform.
|
||||||
// to pass additional options.
|
*
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
prepare (cordovaProject, prepareOptions) {
|
||||||
|
cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path);
|
||||||
|
|
||||||
// Do some basic argument parsing
|
return prepare.call(this, cordovaProject, prepareOptions);
|
||||||
var opts = {};
|
}
|
||||||
|
|
||||||
// Skip cleaning prepared files when not invoking via cordova CLI.
|
/**
|
||||||
opts.noPrepare = true;
|
* 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.
|
||||||
|
*/
|
||||||
|
addPlugin (plugin, installOptions) {
|
||||||
|
var project = AndroidProject.getProjectFile(this.root);
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (!AndroidStudio.isAndroidStudioProject(self.root) && !project.isClean()) {
|
installOptions = installOptions || {};
|
||||||
return self.clean(opts);
|
installOptions.variables = installOptions.variables || {};
|
||||||
|
// Add PACKAGE_NAME variable into vars
|
||||||
|
if (!installOptions.variables.PACKAGE_NAME) {
|
||||||
|
installOptions.variables.PACKAGE_NAME = project.getPackageName();
|
||||||
}
|
}
|
||||||
}).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);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
return Promise.resolve().then(function () {
|
||||||
* Removes an installed plugin from platform.
|
return PluginManager.get(self.platform, self.locations, project).addPlugin(plugin, installOptions);
|
||||||
*
|
}).then(function () {
|
||||||
* 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;
|
if (plugin.getFrameworks(this.platform).length === 0) return;
|
||||||
|
|
||||||
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
||||||
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
// This should pick the correct builder, not just get gradle
|
||||||
|
require('./lib/builders/builders').getBuilder().prepBuildFiles();
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
// CB-11022 Return truthy value to prevent running prepare after
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
.thenResolve(true);
|
.then(() => 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) {
|
* Removes an installed plugin from platform.
|
||||||
// Cast build result to array of build artifacts
|
*
|
||||||
return buildResults.apkPaths.map(function (apkPath) {
|
* Since method accepts PluginInfo instance as input parameter instead of plugin
|
||||||
return {
|
* id, caller shoud take care of managing/storing PluginInfo instances for
|
||||||
buildType: buildResults.buildType,
|
* future uninstalls.
|
||||||
buildMethod: buildResults.buildMethod,
|
*
|
||||||
path: apkPath,
|
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
|
||||||
type: 'apk'
|
* that will be installed.
|
||||||
};
|
*
|
||||||
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
|
* CordovaError instance.
|
||||||
|
*/
|
||||||
|
removePlugin (plugin, uninstallOptions) {
|
||||||
|
var project = AndroidProject.getProjectFile(this.root);
|
||||||
|
|
||||||
|
if (uninstallOptions && uninstallOptions.usePlatformWww === true) {
|
||||||
|
uninstallOptions.usePlatformWww = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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().prepBuildFiles();
|
||||||
|
}.bind(this))
|
||||||
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
|
.then(() => 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.
|
||||||
|
*/
|
||||||
|
build (buildOptions) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
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.paths.map(function (apkPath) {
|
||||||
|
return {
|
||||||
|
buildType: buildResults.buildType,
|
||||||
|
buildMethod: buildResults.buildMethod,
|
||||||
|
path: apkPath,
|
||||||
|
type: path.extname(apkPath).replace(/\./g, '')
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds an application package for current platform and runs it on
|
* Builds an application package for current platform and runs it on
|
||||||
* specified/default device. If no 'device'/'emulator'/'target' options are
|
* specified/default device. If no 'device'/'emulator'/'target' options are
|
||||||
* specified, then tries to run app on default device if connected, otherwise
|
* specified, then tries to run app on default device if connected, otherwise
|
||||||
* runs the app on emulator.
|
* runs the app on emulator.
|
||||||
*
|
*
|
||||||
* @param {Object} runOptions An options object. The structure is the same
|
* @param {Object} runOptions An options object. The structure is the same
|
||||||
* as for build options.
|
* as for build options.
|
||||||
*
|
*
|
||||||
* @return {Promise} A promise either fulfilled if package was built and ran
|
* @return {Promise} A promise either fulfilled if package was built and ran
|
||||||
* successfully, or rejected with CordovaError.
|
* successfully, or rejected with CordovaError.
|
||||||
*/
|
*/
|
||||||
Api.prototype.run = function (runOptions) {
|
run (runOptions) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return require('./lib/check_reqs').run().then(function () {
|
return require('./lib/check_reqs').run().then(function () {
|
||||||
return require('./lib/run').run.call(self, runOptions);
|
return require('./lib/run').run.call(self, runOptions);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans out the build artifacts from platform's directory, and also
|
* Cleans out the build artifacts from platform's directory, and also
|
||||||
* cleans out the platform www directory if called without options specified.
|
* cleans out the platform www directory if called without options specified.
|
||||||
*
|
*
|
||||||
* @return {Promise} Return a promise either fulfilled, or rejected with
|
* @return {Promise} Return a promise either fulfilled, or rejected with
|
||||||
* CordovaError.
|
* CordovaError.
|
||||||
*/
|
*/
|
||||||
Api.prototype.clean = function (cleanOptions) {
|
clean (cleanOptions) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this.android_studio) {
|
|
||||||
// This will lint, checking for null won't
|
// This will lint, checking for null won't
|
||||||
if (typeof cleanOptions === 'undefined') {
|
if (typeof cleanOptions === 'undefined') {
|
||||||
cleanOptions = {};
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return require('./lib/check_reqs').run().then(function () {
|
/**
|
||||||
return require('./lib/build').runClean.call(self, cleanOptions);
|
* Performs a requirements check for current platform. Each platform defines its
|
||||||
}).then(function () {
|
* own set of requirements, which should be resolved before platform can be
|
||||||
return require('./lib/prepare').clean.call(self, cleanOptions);
|
* built successfully.
|
||||||
});
|
*
|
||||||
};
|
* @return {Promise<Requirement[]>} Promise, resolved with set of Requirement
|
||||||
|
* objects for current platform.
|
||||||
|
*/
|
||||||
|
requirements () {
|
||||||
|
return require('./lib/check_reqs').check_all();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a requirements check for current platform. Each platform defines its
|
* Installs platform to specified directory and creates a platform project.
|
||||||
* own set of requirements, which should be resolved before platform can be
|
*
|
||||||
* built successfully.
|
* @param {String} destination Destination directory, where insatll platform to
|
||||||
*
|
* @param {ConfigParser} [config] ConfgiParser instance, used to retrieve
|
||||||
* @return {Promise<Requirement[]>} Promise, resolved with set of Requirement
|
* project creation options, such as package id and project name.
|
||||||
* objects for current platform.
|
* @param {Object} [options] An options object. The most common options are:
|
||||||
*/
|
* @param {String} [options.customTemplate] A path to custom template, that
|
||||||
Api.prototype.requirements = function () {
|
* should override the default one from platform.
|
||||||
return require('./lib/check_reqs').check_all();
|
* @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.
|
||||||
|
*/
|
||||||
|
static createPlatform (destination, config, options, events) {
|
||||||
|
events = setupEvents(events);
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
|
||||||
|
return new Api(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.
|
||||||
|
*/
|
||||||
|
static updatePlatform (destination, options, events) {
|
||||||
|
events = setupEvents(events);
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = require('../../lib/create').update(destination, options, events).then(function (destination) {
|
||||||
|
return new Api(PLATFORM, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static version () {
|
||||||
|
return VERSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Api;
|
module.exports = Api;
|
||||||
|
|||||||
@@ -19,24 +19,25 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var args = process.argv;
|
var args = process.argv;
|
||||||
var Api = require('./Api');
|
var Api = require('./Api');
|
||||||
var nopt = require('nopt');
|
var nopt = require('nopt');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
// Support basic help commands
|
// Support basic help commands
|
||||||
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0)
|
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[2]) >= 0) {
|
||||||
require('./lib/build').help();
|
require('./lib/build').help();
|
||||||
|
}
|
||||||
|
|
||||||
// Do some basic argument parsing
|
// Do some basic argument parsing
|
||||||
var buildOpts = nopt({
|
var buildOpts = nopt({
|
||||||
'verbose' : Boolean,
|
verbose: Boolean,
|
||||||
'silent' : Boolean,
|
silent: Boolean,
|
||||||
'debug' : Boolean,
|
debug: Boolean,
|
||||||
'release' : Boolean,
|
release: Boolean,
|
||||||
'nobuild': Boolean,
|
nobuild: Boolean,
|
||||||
'buildConfig' : path
|
buildConfig: path
|
||||||
}, { 'd' : '--verbose' });
|
}, { d: '--verbose' });
|
||||||
|
|
||||||
// Make buildOptions compatible with PlatformApi build method spec
|
// Make buildOptions compatible with PlatformApi build method spec
|
||||||
buildOpts.argv = buildOpts.argv.original;
|
buildOpts.argv = buildOpts.argv.original;
|
||||||
@@ -44,7 +45,7 @@ buildOpts.argv = buildOpts.argv.original;
|
|||||||
require('./loggingHelper').adjustLoggerLevel(buildOpts);
|
require('./loggingHelper').adjustLoggerLevel(buildOpts);
|
||||||
|
|
||||||
new Api().build(buildOpts)
|
new Api().build(buildOpts)
|
||||||
.catch(function(err) {
|
.catch(function (err) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,11 +20,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var Api = require('./Api');
|
var Api = require('./Api');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var nopt = require('nopt');
|
var nopt = require('nopt');
|
||||||
|
|
||||||
// Support basic help commands
|
// Support basic help commands
|
||||||
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
|
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
|
||||||
console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]));
|
console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]));
|
||||||
console.log('Cleans the project directory.');
|
console.log('Cleans the project directory.');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@@ -32,9 +32,9 @@ if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >=
|
|||||||
|
|
||||||
// Do some basic argument parsing
|
// Do some basic argument parsing
|
||||||
var opts = nopt({
|
var opts = nopt({
|
||||||
'verbose' : Boolean,
|
verbose: Boolean,
|
||||||
'silent' : Boolean
|
silent: Boolean
|
||||||
}, { 'd' : '--verbose' });
|
}, { d: '--verbose' });
|
||||||
|
|
||||||
// Make buildOptions compatible with PlatformApi clean method spec
|
// Make buildOptions compatible with PlatformApi clean method spec
|
||||||
opts.argv = opts.argv.original;
|
opts.argv = opts.argv.original;
|
||||||
@@ -45,7 +45,7 @@ opts.noPrepare = true;
|
|||||||
require('./loggingHelper').adjustLoggerLevel(opts);
|
require('./loggingHelper').adjustLoggerLevel(opts);
|
||||||
|
|
||||||
new Api().clean(opts)
|
new Api().clean(opts)
|
||||||
.catch(function(err) {
|
.catch(function (err) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,10 +17,9 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Q = require('q');
|
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
|
var execa = require('execa');
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
var spawn = require('cordova-common').superspawn.spawn;
|
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
var Adb = {};
|
var Adb = {};
|
||||||
@@ -44,7 +43,7 @@ function isEmulator (line) {
|
|||||||
* devices/emulators
|
* devices/emulators
|
||||||
*/
|
*/
|
||||||
Adb.devices = function (opts) {
|
Adb.devices = function (opts) {
|
||||||
return spawn('adb', ['devices'], {cwd: os.tmpdir()}).then(function (output) {
|
return execa('adb', ['devices'], { cwd: os.tmpdir() }).then(({ stdout: output }) => {
|
||||||
return output.split('\n').filter(function (line) {
|
return output.split('\n').filter(function (line) {
|
||||||
// Filter out either real devices or emulators, depending on options
|
// Filter out either real devices or emulators, depending on options
|
||||||
return (line && opts && opts.emulators) ? isEmulator(line) : isDevice(line);
|
return (line && opts && opts.emulators) ? isEmulator(line) : isDevice(line);
|
||||||
@@ -58,7 +57,7 @@ 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'];
|
var args = ['-s', target, 'install'];
|
||||||
if (opts && opts.replace) args.push('-r');
|
if (opts && opts.replace) args.push('-r');
|
||||||
return spawn('adb', args.concat(packagePath), {cwd: os.tmpdir()}).then(function (output) {
|
return execa('adb', args.concat(packagePath), { cwd: os.tmpdir() }).then(({ stdout: output }) => {
|
||||||
// 'adb install' seems to always returns no error, even if installation fails
|
// 'adb install' seems to always returns no error, even if installation fails
|
||||||
// so we catching output to detect installation failure
|
// so we catching output to detect installation failure
|
||||||
if (output.match(/Failure/)) {
|
if (output.match(/Failure/)) {
|
||||||
@@ -70,31 +69,30 @@ Adb.install = function (target, packagePath, opts) {
|
|||||||
'\nEither uninstall an app or increment the versionCode.';
|
'\nEither uninstall an app or increment the versionCode.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return Q.reject(new CordovaError('Failed to install apk to device: ' + output));
|
return Promise.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 spawn('adb', ['-s', target, 'uninstall', packageId], {cwd: os.tmpdir()});
|
return execa('adb', ['-s', target, 'uninstall', packageId], { cwd: os.tmpdir() }).then(({ stdout }) => stdout);
|
||||||
};
|
};
|
||||||
|
|
||||||
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 + '...');
|
||||||
var args = ['-s', target, 'shell'];
|
var args = ['-s', target, 'shell'];
|
||||||
shellCommand = shellCommand.split(/\s+/);
|
shellCommand = shellCommand.split(/\s+/);
|
||||||
return spawn('adb', args.concat(shellCommand), {cwd: os.tmpdir()}).catch(function (output) {
|
return execa('adb', args.concat(shellCommand), { cwd: os.tmpdir() })
|
||||||
return Q.reject(new CordovaError('Failed to execute shell command "' +
|
.then(({ stdout }) => stdout)
|
||||||
shellCommand + '"" on device: ' + output));
|
.catch(error => Promise.reject(new CordovaError(`Failed to execute shell command "${shellCommand}" on device: ${error}`)));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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(function (output) {
|
return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName).catch((error) => {
|
||||||
return Q.reject(new CordovaError('Failed to start application "' +
|
return Promise.reject(new CordovaError('Failed to start application "' +
|
||||||
activityName + '"" on device: ' + output));
|
activityName + '"" on device: ' + error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,143 +18,111 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var et = require('elementtree');
|
|
||||||
var xml = require('cordova-common').xmlHelpers;
|
var xml = require('cordova-common').xmlHelpers;
|
||||||
|
|
||||||
var DEFAULT_ORIENTATION = 'default';
|
var DEFAULT_ORIENTATION = 'default';
|
||||||
|
|
||||||
/** Wraps an AndroidManifest file */
|
/** Wraps an AndroidManifest file */
|
||||||
function AndroidManifest (path) {
|
class AndroidManifest {
|
||||||
this.path = path;
|
constructor (path) {
|
||||||
this.doc = xml.parseElementtreeSync(path);
|
this.path = path;
|
||||||
if (this.doc.getroot().tag !== 'manifest') {
|
this.doc = xml.parseElementtreeSync(path);
|
||||||
throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
|
if (this.doc.getroot().tag !== 'manifest') {
|
||||||
|
throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getVersionName () {
|
||||||
|
return this.doc.getroot().attrib['android:versionName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
setVersionName (versionName) {
|
||||||
|
this.doc.getroot().attrib['android:versionName'] = versionName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
getVersionCode () {
|
||||||
|
return this.doc.getroot().attrib['android:versionCode'];
|
||||||
|
}
|
||||||
|
|
||||||
|
setVersionCode (versionCode) {
|
||||||
|
this.doc.getroot().attrib['android:versionCode'] = versionCode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPackageId () {
|
||||||
|
return this.doc.getroot().attrib.package;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPackageId (pkgId) {
|
||||||
|
this.doc.getroot().attrib.package = pkgId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
getActivity () {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getDebuggable () {
|
||||||
|
return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
setDebuggable (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.
|
||||||
|
*/
|
||||||
|
write (destPath) {
|
||||||
|
fs.writeFileSync(destPath || this.path, this.doc.write({ indent: 4 }), 'utf-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
module.exports = AndroidManifest;
|
||||||
|
|
||||||
function capitalize (str) {
|
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ var fs = require('fs');
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var properties_parser = require('properties-parser');
|
var properties_parser = require('properties-parser');
|
||||||
var AndroidManifest = require('./AndroidManifest');
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
var AndroidStudio = require('./AndroidStudio');
|
|
||||||
var pluginHandlers = require('./pluginHandlers');
|
var pluginHandlers = require('./pluginHandlers');
|
||||||
|
|
||||||
var projectFileCache = {};
|
var projectFileCache = {};
|
||||||
@@ -56,154 +55,148 @@ function getRelativeLibraryPath (parentDir, subDir) {
|
|||||||
return (path.sep === '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;
|
return (path.sep === '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AndroidProject (projectDir) {
|
class AndroidProject {
|
||||||
this._propertiesEditors = {};
|
constructor (projectDir) {
|
||||||
this._subProjectDirs = {};
|
this._propertiesEditors = {};
|
||||||
this._dirty = false;
|
this._subProjectDirs = {};
|
||||||
this.projectDir = projectDir;
|
this._dirty = false;
|
||||||
this.platformWww = path.join(this.projectDir, 'platform_www');
|
this.projectDir = projectDir;
|
||||||
this.www = path.join(this.projectDir, 'assets/www');
|
this.platformWww = path.join(this.projectDir, 'platform_www');
|
||||||
if (AndroidStudio.isAndroidStudioProject(projectDir) === true) {
|
|
||||||
this.www = path.join(this.projectDir, 'app/src/main/assets/www');
|
this.www = path.join(this.projectDir, 'app/src/main/assets/www');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
getPackageName () {
|
||||||
|
var manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
|
||||||
|
return new AndroidManifest(manifestPath).getPackageId();
|
||||||
|
}
|
||||||
|
|
||||||
|
getCustomSubprojectRelativeDir (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
addSubProject (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeSubProject (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
addGradleReference (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeGradleReference (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
addSystemLibrary (parentDir, value) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
addToPropertyList(parentProperties, 'cordova.system.library', value);
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeSystemLibrary (parentDir, value) {
|
||||||
|
var parentProjectFile = path.resolve(parentDir, 'project.properties');
|
||||||
|
var parentProperties = this._getPropertiesFile(parentProjectFile);
|
||||||
|
removeFromPropertyList(parentProperties, 'cordova.system.library', value);
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
write () {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getInstaller (type) {
|
||||||
|
return pluginHandlers.getInstaller(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
getUninstaller (type) {
|
||||||
|
return pluginHandlers.getUninstaller(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This checks if an Android project is clean or has old build artifacts
|
||||||
|
*/
|
||||||
|
isClean () {
|
||||||
|
var build_path = path.join(this.projectDir, 'build');
|
||||||
|
// If the build directory doesn't exist, it's clean
|
||||||
|
return !(fs.existsSync(build_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
_getPropertiesFile (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];
|
||||||
|
}
|
||||||
|
|
||||||
|
static getProjectFile (projectDir) {
|
||||||
|
if (!projectFileCache[projectDir]) {
|
||||||
|
projectFileCache[projectDir] = new AndroidProject(projectDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectFileCache[projectDir];
|
||||||
|
}
|
||||||
|
|
||||||
|
static purgeCache (projectDir) {
|
||||||
|
if (projectDir) {
|
||||||
|
delete projectFileCache[projectDir];
|
||||||
|
} else {
|
||||||
|
projectFileCache = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
module.exports = AndroidProject;
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const PackageType = {
|
||||||
|
APK: 'apk',
|
||||||
|
BUNDLE: 'bundle'
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = PackageType;
|
||||||
@@ -17,8 +17,7 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Q = require('q');
|
const execa = require('execa');
|
||||||
var superspawn = require('cordova-common').superspawn;
|
|
||||||
|
|
||||||
var 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:
|
||||||
@@ -30,17 +29,14 @@ var 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) {
|
||||||
var suffix_a = a.match(suffix_number_regex);
|
let suffix_a = a.match(suffix_number_regex);
|
||||||
var suffix_b = b.match(suffix_number_regex);
|
let suffix_b = b.match(suffix_number_regex);
|
||||||
if (suffix_a && suffix_b) {
|
// If no number is detected (eg: preview version like android-R),
|
||||||
// If the two targets being compared have suffixes, return less than
|
// designate a suffix of 0 so it gets moved to the end
|
||||||
// zero, or greater than zero, based on which suffix is larger.
|
suffix_a = suffix_a || ['0', '0'];
|
||||||
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
suffix_b = suffix_b || ['0', '0'];
|
||||||
} else {
|
// Return < zero, or > zero, based on which suffix is larger.
|
||||||
// If no suffix numbers were detected, leave the order as-is between
|
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
||||||
// elements a and b.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.print_newest_available_sdk_target = function () {
|
module.exports.print_newest_available_sdk_target = function () {
|
||||||
@@ -50,6 +46,8 @@ 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,
|
||||||
@@ -65,6 +63,7 @@ module.exports.version_string_to_api_level = {
|
|||||||
'7.1.1': 25,
|
'7.1.1': 25,
|
||||||
'8.0': 26
|
'8.0': 26
|
||||||
};
|
};
|
||||||
|
/* eslint-enable quote-props */
|
||||||
|
|
||||||
function parse_targets (output) {
|
function parse_targets (output) {
|
||||||
var target_out = output.split('\n');
|
var target_out = output.split('\n');
|
||||||
@@ -78,11 +77,11 @@ function parse_targets (output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.list_targets_with_android = function () {
|
module.exports.list_targets_with_android = function () {
|
||||||
return superspawn.spawn('android', ['list', 'target']).then(parse_targets);
|
return execa('android', ['list', 'target']).then(result => parse_targets(result.stdout));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.list_targets_with_avdmanager = function () {
|
module.exports.list_targets_with_avdmanager = function () {
|
||||||
return superspawn.spawn('avdmanager', ['list', 'target']).then(parse_targets);
|
return execa('avdmanager', ['list', 'target']).then(result => parse_targets(result.stdout));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.list_targets = function () {
|
module.exports.list_targets = function () {
|
||||||
@@ -95,7 +94,7 @@ module.exports.list_targets = function () {
|
|||||||
} else throw err;
|
} else throw err;
|
||||||
}).then(function (targets) {
|
}).then(function (targets) {
|
||||||
if (targets.length === 0) {
|
if (targets.length === 0) {
|
||||||
return Q.reject(new Error('No android targets (SDKs) installed!'));
|
return Promise.reject(new Error('No android targets (SDKs) installed!'));
|
||||||
}
|
}
|
||||||
return targets;
|
return targets;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,7 +17,6 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Q = require('q');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var nopt = require('nopt');
|
var nopt = require('nopt');
|
||||||
@@ -28,48 +25,40 @@ var Adb = require('./Adb');
|
|||||||
|
|
||||||
var builders = require('./builders/builders');
|
var builders = require('./builders/builders');
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
var spawn = require('cordova-common').superspawn.spawn;
|
const execa = require('execa');
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var PackageType = require('./PackageType');
|
||||||
|
|
||||||
|
module.exports.parseBuildOptions = parseOpts;
|
||||||
function parseOpts (options, resolvedTarget, projectRoot) {
|
function parseOpts (options, resolvedTarget, projectRoot) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.argv = nopt({
|
options.argv = nopt({
|
||||||
gradle: Boolean,
|
|
||||||
studio: Boolean,
|
|
||||||
prepenv: Boolean,
|
prepenv: Boolean,
|
||||||
versionCode: String,
|
versionCode: String,
|
||||||
minSdkVersion: String,
|
minSdkVersion: String,
|
||||||
|
maxSdkVersion: String,
|
||||||
|
targetSdkVersion: String,
|
||||||
gradleArg: [String, Array],
|
gradleArg: [String, Array],
|
||||||
keystore: path,
|
keystore: path,
|
||||||
alias: String,
|
alias: String,
|
||||||
storePassword: String,
|
storePassword: String,
|
||||||
password: String,
|
password: String,
|
||||||
keystoreType: String
|
keystoreType: String,
|
||||||
|
packageType: String
|
||||||
}, {}, options.argv, 0);
|
}, {}, options.argv, 0);
|
||||||
|
|
||||||
// Android Studio Build method is the default
|
// Android Studio Build method is the default
|
||||||
var ret = {
|
var ret = {
|
||||||
buildType: options.release ? 'release' : 'debug',
|
buildType: options.release ? 'release' : 'debug',
|
||||||
buildMethod: process.env.ANDROID_BUILD || 'studio',
|
|
||||||
prepEnv: options.argv.prepenv,
|
prepEnv: options.argv.prepenv,
|
||||||
arch: resolvedTarget && resolvedTarget.arch,
|
arch: resolvedTarget && resolvedTarget.arch,
|
||||||
extraArgs: []
|
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.versionCode) { ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode); }
|
||||||
|
|
||||||
if (options.argv.minSdkVersion) { ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion); }
|
if (options.argv.minSdkVersion) { ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion); }
|
||||||
|
if (options.argv.maxSdkVersion) { ret.extraArgs.push('-PcdvMaxSdkVersion=' + options.argv.maxSdkVersion); }
|
||||||
|
if (options.argv.targetSdkVersion) { ret.extraArgs.push('-PcdvTargetSdkVersion=' + options.argv.targetSdkVersion); }
|
||||||
if (options.argv.gradleArg) {
|
if (options.argv.gradleArg) {
|
||||||
ret.extraArgs = ret.extraArgs.concat(options.argv.gradleArg);
|
ret.extraArgs = ret.extraArgs.concat(options.argv.gradleArg);
|
||||||
}
|
}
|
||||||
@@ -78,14 +67,14 @@ function parseOpts (options, resolvedTarget, projectRoot) {
|
|||||||
|
|
||||||
if (options.argv.keystore) { packageArgs.keystore = path.relative(projectRoot, path.resolve(options.argv.keystore)); }
|
if (options.argv.keystore) { packageArgs.keystore = path.relative(projectRoot, path.resolve(options.argv.keystore)); }
|
||||||
|
|
||||||
['alias', 'storePassword', 'password', 'keystoreType'].forEach(function (flagName) {
|
['alias', 'storePassword', 'password', 'keystoreType', 'packageType'].forEach(function (flagName) {
|
||||||
if (options.argv[flagName]) { packageArgs[flagName] = options.argv[flagName]; }
|
if (options.argv[flagName]) { packageArgs[flagName] = options.argv[flagName]; }
|
||||||
});
|
});
|
||||||
|
|
||||||
var buildConfig = options.buildConfig;
|
var buildConfig = options.buildConfig;
|
||||||
|
|
||||||
// If some values are not specified as command line arguments - use build config to supplement them.
|
// If some values are not specified as command line arguments - use build config to supplement them.
|
||||||
// Command line arguemnts have precedence over build config.
|
// Command line arguments have precedence over build config.
|
||||||
if (buildConfig) {
|
if (buildConfig) {
|
||||||
if (!fs.existsSync(buildConfig)) {
|
if (!fs.existsSync(buildConfig)) {
|
||||||
throw new Error('Specified build config file does not exist: ' + buildConfig);
|
throw new Error('Specified build config file does not exist: ' + buildConfig);
|
||||||
@@ -103,7 +92,7 @@ function parseOpts (options, resolvedTarget, projectRoot) {
|
|||||||
events.emit('log', 'Reading the keystore from: ' + packageArgs.keystore);
|
events.emit('log', 'Reading the keystore from: ' + packageArgs.keystore);
|
||||||
}
|
}
|
||||||
|
|
||||||
['alias', 'storePassword', 'password', 'keystoreType'].forEach(function (key) {
|
['alias', 'storePassword', 'password', 'keystoreType', 'packageType'].forEach(function (key) {
|
||||||
packageArgs[key] = packageArgs[key] || androidInfo[key];
|
packageArgs[key] = packageArgs[key] || androidInfo[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -115,11 +104,38 @@ function parseOpts (options, resolvedTarget, projectRoot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ret.packageInfo) {
|
if (!ret.packageInfo) {
|
||||||
if (Object.keys(packageArgs).length > 0) {
|
// The following loop is to decide whether to print a warning about generating a signed archive
|
||||||
|
// We only want to produce a warning if they are using a config property that is related to signing, but
|
||||||
|
// missing the required properties for signing. We don't want to produce a warning if they are simply
|
||||||
|
// using a build property that isn't related to signing, such as --packageType
|
||||||
|
let shouldWarn = false;
|
||||||
|
const signingKeys = ['keystore', 'alias', 'storePassword', 'password', 'keystoreType'];
|
||||||
|
|
||||||
|
for (const key in packageArgs) {
|
||||||
|
if (!shouldWarn && signingKeys.indexOf(key) > -1) {
|
||||||
|
// If we enter this condition, we have a key used for signing a build,
|
||||||
|
// but we are missing some required signing properties
|
||||||
|
shouldWarn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldWarn) {
|
||||||
events.emit('warn', '\'keystore\' and \'alias\' need to be specified to generate a signed archive.');
|
events.emit('warn', '\'keystore\' and \'alias\' need to be specified to generate a signed archive.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packageArgs.packageType) {
|
||||||
|
const VALID_PACKAGE_TYPES = [PackageType.APK, PackageType.BUNDLE];
|
||||||
|
if (VALID_PACKAGE_TYPES.indexOf(packageArgs.packageType) === -1) {
|
||||||
|
events.emit('warn', '"' + packageArgs.packageType + '" is an invalid packageType. Valid values are: ' + VALID_PACKAGE_TYPES.join(', ') + '\nDefaulting packageType to ' + PackageType.APK);
|
||||||
|
ret.packageType = PackageType.APK;
|
||||||
|
} else {
|
||||||
|
ret.packageType = packageArgs.packageType;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.packageType = PackageType.APK;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +145,8 @@ function parseOpts (options, resolvedTarget, projectRoot) {
|
|||||||
*/
|
*/
|
||||||
module.exports.runClean = function (options) {
|
module.exports.runClean = function (options) {
|
||||||
var opts = parseOpts(options, null, this.root);
|
var opts = parseOpts(options, null, this.root);
|
||||||
var builder = builders.getBuilder(opts.buildMethod);
|
var builder = builders.getBuilder();
|
||||||
|
|
||||||
return builder.prepEnv(opts).then(function () {
|
return builder.prepEnv(opts).then(function () {
|
||||||
return builder.clean(opts);
|
return builder.clean(opts);
|
||||||
});
|
});
|
||||||
@@ -149,20 +166,26 @@ module.exports.runClean = function (options) {
|
|||||||
*/
|
*/
|
||||||
module.exports.run = function (options, optResolvedTarget) {
|
module.exports.run = function (options, optResolvedTarget) {
|
||||||
var opts = parseOpts(options, optResolvedTarget, this.root);
|
var opts = parseOpts(options, optResolvedTarget, this.root);
|
||||||
console.log(opts.buildMethod);
|
var builder = builders.getBuilder();
|
||||||
var builder = builders.getBuilder(opts.buildMethod);
|
|
||||||
return builder.prepEnv(opts).then(function () {
|
return builder.prepEnv(opts).then(function () {
|
||||||
if (opts.prepEnv) {
|
if (opts.prepEnv) {
|
||||||
events.emit('verbose', 'Build file successfully prepared.');
|
events.emit('verbose', 'Build file successfully prepared.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return builder.build(opts).then(function () {
|
return builder.build(opts).then(function () {
|
||||||
var apkPaths = builder.findOutputApks(opts.buildType, opts.arch);
|
var paths;
|
||||||
events.emit('log', 'Built the following apk(s): \n\t' + apkPaths.join('\n\t'));
|
if (opts.packageType === PackageType.BUNDLE) {
|
||||||
|
paths = builder.findOutputBundles(opts.buildType);
|
||||||
|
events.emit('log', 'Built the following bundle(s): \n\t' + paths.join('\n\t'));
|
||||||
|
} else {
|
||||||
|
paths = builder.findOutputApks(opts.buildType, opts.arch);
|
||||||
|
events.emit('log', 'Built the following apk(s): \n\t' + paths.join('\n\t'));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apkPaths: apkPaths,
|
paths: paths,
|
||||||
buildType: opts.buildType,
|
buildType: opts.buildType
|
||||||
buildMethod: opts.buildMethod
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -178,27 +201,37 @@ module.exports.detectArchitecture = function (target) {
|
|||||||
return /intel/i.exec(output) ? 'x86' : 'arm';
|
return /intel/i.exec(output) ? 'x86' : 'arm';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function timeout (ms, err) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => reject(err), ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
// It sometimes happens (at least on OS X), that this command will hang forever.
|
// 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.
|
// 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) {
|
return Promise.race([
|
||||||
|
helper(),
|
||||||
|
timeout(5000, new CordovaError(
|
||||||
|
'Device communication timed out. Try unplugging & replugging the device.'
|
||||||
|
))
|
||||||
|
]).catch(err => {
|
||||||
if (/timed out/.exec('' + err)) {
|
if (/timed out/.exec('' + err)) {
|
||||||
// adb kill-server doesn't seem to do the trick.
|
// adb kill-server doesn't seem to do the trick.
|
||||||
// Could probably find a x-platform version of killall, but I'm not actually
|
// Could probably find a x-platform version of killall, but I'm not actually
|
||||||
// sure that this scenario even happens on non-OSX machines.
|
// 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.');
|
events.emit('verbose', 'adb timed out while detecting device/emulator architecture. Killing adb and trying again.');
|
||||||
return spawn('killall', ['adb']).then(function () {
|
return execa('killall', ['adb']).then(function () {
|
||||||
return helper().then(null, function () {
|
return helper().then(null, function () {
|
||||||
// The double kill is sadly often necessary, at least on mac.
|
// 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.');
|
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 execa('killall', ['adb']).then(function () {
|
||||||
return helper().then(null, 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.'));
|
return Promise.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
// For non-killall OS's.
|
// For non-killall OS's.
|
||||||
return Q.reject(err);
|
return Promise.reject(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
@@ -229,45 +262,23 @@ module.exports.findBestApkForArchitecture = function (buildResults, arch) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function PackageInfo (keystore, alias, storePassword, password, keystoreType) {
|
function PackageInfo (keystore, alias, storePassword, password, keystoreType) {
|
||||||
this.keystore = {
|
const createNameKeyObject = (name, value) => ({ name, value: value.replace(/\\/g, '\\\\') });
|
||||||
'name': 'key.store',
|
|
||||||
'value': keystore
|
this.data = [
|
||||||
};
|
createNameKeyObject('key.store', keystore),
|
||||||
this.alias = {
|
createNameKeyObject('key.alias', alias)
|
||||||
'name': 'key.alias',
|
];
|
||||||
'value': alias
|
|
||||||
};
|
if (storePassword) this.data.push(createNameKeyObject('key.store.password', storePassword));
|
||||||
if (storePassword) {
|
if (password) this.data.push(createNameKeyObject('key.alias.password', password));
|
||||||
this.storePassword = {
|
if (keystoreType) this.data.push(createNameKeyObject('key.store.type', keystoreType));
|
||||||
'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 = {
|
PackageInfo.prototype = {
|
||||||
toProperties: function () {
|
appendToProperties: function (propertiesParser) {
|
||||||
var self = this;
|
for (const { name, value } of this.data) propertiesParser.set(name, value);
|
||||||
var result = '';
|
|
||||||
Object.keys(self).forEach(function (key) {
|
propertiesParser.save();
|
||||||
result += self[key].name;
|
|
||||||
result += '=';
|
|
||||||
result += self[key].value.replace(/\\/g, '\\\\');
|
|
||||||
result += '\n';
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -276,13 +287,14 @@ module.exports.help = function () {
|
|||||||
console.log('Flags:');
|
console.log('Flags:');
|
||||||
console.log(' \'--debug\': will build project in debug mode (default)');
|
console.log(' \'--debug\': will build project in debug mode (default)');
|
||||||
console.log(' \'--release\': will build project for release');
|
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(' \'--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(' \'--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(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs.');
|
||||||
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs. Requires --gradle.');
|
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build.');
|
||||||
|
console.log(' \'--maxSdkVersion=#\': Override maxSdkVersion for this build. (Not Recommended)');
|
||||||
|
console.log(' \'--targetSdkVersion=#\': Override targetSdkVersion for this build.');
|
||||||
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(' \'--gradleArg=<gradle command line arg>\': Extra args to pass to the gradle command. Use one flag per arg. Ex. --gradleArg=-PcdvBuildMultipleApks=true');
|
||||||
|
console.log(' \'--packageType=<apk|bundle>\': Builds an APK or a bundle');
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Signed APK flags (overwrites debug/release-signing.proprties) :');
|
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(' \'--keystore=<path to keystore>\': Key store used to build a signed archive. (Required)');
|
||||||
|
|||||||
@@ -1,124 +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.
|
|
||||||
*/
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
@@ -1,330 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
/*
|
||||||
|
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-extra');
|
||||||
|
var path = require('path');
|
||||||
|
const execa = require('execa');
|
||||||
|
var events = require('cordova-common').events;
|
||||||
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
var check_reqs = require('../check_reqs');
|
||||||
|
var PackageType = require('../PackageType');
|
||||||
|
const { createEditor } = require('properties-parser');
|
||||||
|
|
||||||
|
const MARKER = 'YOUR CHANGES WILL BE ERASED!';
|
||||||
|
const SIGNING_PROPERTIES = '-signing.properties';
|
||||||
|
const TEMPLATE =
|
||||||
|
'# This file is automatically generated.\n' +
|
||||||
|
'# Do not modify this file -- ' + MARKER + '\n';
|
||||||
|
|
||||||
|
const archSpecificRegex = /-x86|-arm/;
|
||||||
|
const unsignedBuildRegex = /-unsigned/;
|
||||||
|
|
||||||
|
const fileSorter = (filePathA, filePathB) => {
|
||||||
|
const archSpecificA = archSpecificRegex.test(filePathA);
|
||||||
|
const archSpecificB = archSpecificRegex.test(filePathB);
|
||||||
|
|
||||||
|
// If they are not equal, then sort by specific archs after generic ones
|
||||||
|
if (archSpecificA !== archSpecificB) {
|
||||||
|
return archSpecificA < archSpecificB ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, move onto the next sort item, which is by sorting unsigned bulds after signed ones
|
||||||
|
const unsignedA = unsignedBuildRegex.test(filePathA);
|
||||||
|
const unsignedB = unsignedBuildRegex.test(filePathB);
|
||||||
|
|
||||||
|
if (unsignedA !== unsignedB) {
|
||||||
|
return unsignedA < unsignedB ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then, sort by modification time, latest first
|
||||||
|
const modTimeA = fs.statSync(filePathA).mtime.getTime();
|
||||||
|
const modTimeB = fs.statSync(filePathB).mtime.getTime();
|
||||||
|
|
||||||
|
if (modTimeA !== modTimeB) {
|
||||||
|
return modTimeA < modTimeB ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, if all above is the same, sort by file name length, ascending
|
||||||
|
return filePathB.length < filePathA.length ? -1 : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the provided directory does not exist or extension is missing, return an empty array.
|
||||||
|
* If the director exists, loop the directories and collect list of files matching the extension.
|
||||||
|
*
|
||||||
|
* @param {String} dir Directory to scan
|
||||||
|
* @param {String} extension
|
||||||
|
*/
|
||||||
|
function recursivelyFindFiles (dir, extension) {
|
||||||
|
if (!fs.existsSync(dir) || !extension) return [];
|
||||||
|
|
||||||
|
const files = fs.readdirSync(dir, { withFileTypes: true })
|
||||||
|
.map(entry => {
|
||||||
|
const item = path.resolve(dir, entry.name);
|
||||||
|
|
||||||
|
if (entry.isDirectory()) return recursivelyFindFiles(item, extension);
|
||||||
|
if (path.extname(entry.name) === `.${extension}`) return item;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.prototype.concat(...files)
|
||||||
|
.filter(file => file !== false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} dir
|
||||||
|
* @param {String} build_type
|
||||||
|
* @param {String} arch
|
||||||
|
* @param {String} extension
|
||||||
|
*/
|
||||||
|
function findOutputFilesHelper (dir, build_type, arch, extension) {
|
||||||
|
let files = recursivelyFindFiles(path.resolve(dir, build_type), extension);
|
||||||
|
|
||||||
|
if (files.length === 0) return files;
|
||||||
|
|
||||||
|
// Assume arch-specific build if newest apk has -x86 or -arm.
|
||||||
|
const archSpecific = !!/-x86|-arm/.exec(path.basename(files[0]));
|
||||||
|
|
||||||
|
// And show only arch-specific ones (or non-arch-specific)
|
||||||
|
files = files.filter(p => !!/-x86|-arm/.exec(path.basename(p)) === archSpecific);
|
||||||
|
|
||||||
|
if (archSpecific && files.length > 1 && arch) {
|
||||||
|
files = files.filter(p => path.basename(p).indexOf('-' + arch) !== -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProjectBuilder {
|
||||||
|
constructor (rootDirectory) {
|
||||||
|
this.root = rootDirectory || path.resolve(__dirname, '../../..');
|
||||||
|
this.apkDir = path.join(this.root, 'app', 'build', 'outputs', 'apk');
|
||||||
|
this.aabDir = path.join(this.root, 'app', 'build', 'outputs', 'bundle');
|
||||||
|
}
|
||||||
|
|
||||||
|
getArgs (cmd, opts) {
|
||||||
|
let args;
|
||||||
|
let buildCmd = cmd;
|
||||||
|
if (opts.packageType === PackageType.BUNDLE) {
|
||||||
|
if (cmd === 'release') {
|
||||||
|
buildCmd = ':app:bundleRelease';
|
||||||
|
} else if (cmd === 'debug') {
|
||||||
|
buildCmd = ':app:bundleDebug';
|
||||||
|
}
|
||||||
|
|
||||||
|
args = [buildCmd, '-b', path.join(this.root, 'build.gradle')];
|
||||||
|
} else {
|
||||||
|
if (cmd === 'release') {
|
||||||
|
buildCmd = 'cdvBuildRelease';
|
||||||
|
} else if (cmd === 'debug') {
|
||||||
|
buildCmd = 'cdvBuildDebug';
|
||||||
|
}
|
||||||
|
|
||||||
|
args = [buildCmd, '-b', path.join(this.root, 'build.gradle')];
|
||||||
|
|
||||||
|
if (opts.arch) {
|
||||||
|
args.push('-PcdvBuildArch=' + opts.arch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push.apply(args, opts.extraArgs);
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This returns a promise
|
||||||
|
*/
|
||||||
|
runGradleWrapper (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 execa(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], { stdio: 'inherit' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readProjectProperties () {
|
||||||
|
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)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
extractRealProjectNameFromManifest () {
|
||||||
|
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.
|
||||||
|
prepBuildFiles () {
|
||||||
|
// 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) {
|
||||||
|
fs.copySync(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) {
|
||||||
|
events.emit('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 += ' implementation "' + 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
prepEnv (opts) {
|
||||||
|
var self = this;
|
||||||
|
return check_reqs.check_gradle()
|
||||||
|
.then(function (gradlePath) {
|
||||||
|
return self.runGradleWrapper(gradlePath);
|
||||||
|
}).then(function () {
|
||||||
|
return self.prepBuildFiles();
|
||||||
|
}).then(() => {
|
||||||
|
// update/set the distributionUrl in the gradle-wrapper.properties
|
||||||
|
const gradleWrapperPropertiesPath = path.join(self.root, 'gradle/wrapper/gradle-wrapper.properties');
|
||||||
|
const gradleWrapperProperties = createEditor(gradleWrapperPropertiesPath);
|
||||||
|
const distributionUrl = process.env.CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL || 'https://services.gradle.org/distributions/gradle-6.5-all.zip';
|
||||||
|
gradleWrapperProperties.set('distributionUrl', distributionUrl);
|
||||||
|
gradleWrapperProperties.save();
|
||||||
|
|
||||||
|
events.emit('verbose', `Gradle Distribution URL: ${distributionUrl}`);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
const signingPropertiesPath = path.join(self.root, `${opts.buildType}${SIGNING_PROPERTIES}`);
|
||||||
|
|
||||||
|
if (fs.existsSync(signingPropertiesPath)) fs.removeSync(signingPropertiesPath);
|
||||||
|
if (opts.packageInfo) {
|
||||||
|
fs.ensureFileSync(signingPropertiesPath);
|
||||||
|
const signingProperties = createEditor(signingPropertiesPath);
|
||||||
|
signingProperties.addHeadComment(TEMPLATE);
|
||||||
|
opts.packageInfo.appendToProperties(signingProperties);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Builds the project with gradle.
|
||||||
|
* Returns a promise.
|
||||||
|
*/
|
||||||
|
build (opts) {
|
||||||
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
|
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
||||||
|
|
||||||
|
return execa(wrapper, args, { stdio: 'inherit' })
|
||||||
|
.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.
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
clean (opts) {
|
||||||
|
const wrapper = path.join(this.root, 'gradlew');
|
||||||
|
const args = this.getArgs('clean', opts);
|
||||||
|
return execa(wrapper, args, { stdio: 'inherit' })
|
||||||
|
.then(() => {
|
||||||
|
fs.removeSync(path.join(this.root, 'out'));
|
||||||
|
|
||||||
|
['debug', 'release'].map(config => path.join(this.root, `${config}${SIGNING_PROPERTIES}`))
|
||||||
|
.forEach(file => {
|
||||||
|
const hasFile = fs.existsSync(file);
|
||||||
|
const hasMarker = hasFile && fs.readFileSync(file, 'utf8')
|
||||||
|
.includes(MARKER);
|
||||||
|
|
||||||
|
if (hasFile && hasMarker) fs.removeSync(file);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
findOutputApks (build_type, arch) {
|
||||||
|
return findOutputFilesHelper(this.apkDir, build_type, arch, 'apk').sort(fileSorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
findOutputBundles (build_type) {
|
||||||
|
return findOutputFilesHelper(this.aabDir, build_type, false, 'aab').sort(fileSorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchBuildResults (build_type, arch) {
|
||||||
|
return {
|
||||||
|
apkPaths: this.findOutputApks(build_type, arch),
|
||||||
|
buildType: build_type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ProjectBuilder;
|
||||||
@@ -1,302 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,46 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
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
|
||||||
distributed with this work for additional information
|
distributed with this work for additional information
|
||||||
regarding copyright ownership. The ASF licenses this file
|
regarding copyright ownership. The ASF licenses this file
|
||||||
to you under the Apache License, Version 2.0 (the
|
to you under the Apache License, Version 2.0 (the
|
||||||
"License"); you may not use this file except in compliance
|
"License"); you may not use this file except in compliance
|
||||||
with the License. You may obtain a copy of the License at
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the License is distributed on an
|
software distributed under the License is distributed on an
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
KIND, either express or implied. See the License for the
|
KIND, either express or implied. See the License for the
|
||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
const CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
var knownBuilders = {
|
|
||||||
gradle: 'GradleBuilder',
|
|
||||||
studio: 'StudioBuilder',
|
|
||||||
none: 'GenericBuilder'
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method that instantiates and returns a builder for specified build
|
* Helper method that instantiates and returns a builder for specified build type.
|
||||||
* type.
|
|
||||||
*
|
*
|
||||||
* @param {String} builderType Builder name to construct and return. Must
|
* @return {Builder} A builder instance for specified build type.
|
||||||
* be one of 'ant', 'gradle' or 'none'
|
|
||||||
*
|
|
||||||
* @return {Builder} A builder instance for specified build type.
|
|
||||||
*/
|
*/
|
||||||
module.exports.getBuilder = function (builderType, projectRoot) {
|
module.exports.getBuilder = function (projectPath) {
|
||||||
if (!knownBuilders[builderType]) { throw new CordovaError('Builder ' + builderType + ' is not supported.'); }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var Builder = require('./' + knownBuilders[builderType]);
|
const Builder = require('./ProjectBuilder');
|
||||||
return new Builder(projectRoot);
|
return new Builder(projectPath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new CordovaError('Failed to instantiate ' + knownBuilders[builderType] + ' builder: ' + err);
|
throw new CordovaError('Failed to instantiate ProjectBuilder builder: ' + err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,37 +17,37 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint sub:true */
|
const execa = require('execa');
|
||||||
|
|
||||||
var shelljs = require('shelljs');
|
|
||||||
var child_process = require('child_process');
|
|
||||||
var Q = require('q');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
var fs = require('fs-extra');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
|
var which = require('which');
|
||||||
var REPO_ROOT = path.join(__dirname, '..', '..', '..', '..');
|
var REPO_ROOT = path.join(__dirname, '..', '..', '..', '..');
|
||||||
var PROJECT_ROOT = path.join(__dirname, '..', '..');
|
var PROJECT_ROOT = path.join(__dirname, '..', '..');
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
const { CordovaError, ConfigParser, events } = require('cordova-common');
|
||||||
var superspawn = require('cordova-common').superspawn;
|
|
||||||
var android_sdk = require('./android_sdk');
|
var android_sdk = require('./android_sdk');
|
||||||
|
const { createEditor } = require('properties-parser');
|
||||||
|
|
||||||
function forgivingWhichSync (cmd) {
|
function forgivingWhichSync (cmd) {
|
||||||
try {
|
const whichResult = which.sync(cmd, { nothrow: true });
|
||||||
return fs.realpathSync(shelljs.which(cmd));
|
|
||||||
} catch (e) {
|
// On null, returns empty string to maintain backwards compatibility
|
||||||
return '';
|
// realpathSync follows symlinks
|
||||||
}
|
return whichResult === null ? '' : fs.realpathSync(whichResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryCommand (cmd, errMsg, catchStderr) {
|
function getJDKDirectory (directory) {
|
||||||
var d = Q.defer();
|
const p = path.resolve(directory, 'java');
|
||||||
child_process.exec(cmd, function (err, stdout, stderr) {
|
if (fs.existsSync(p)) {
|
||||||
if (err) d.reject(new CordovaError(errMsg));
|
const directories = fs.readdirSync(p);
|
||||||
// Sometimes it is necessary to return an stderr instead of stdout in case of success, since
|
for (let i = 0; i < directories.length; i++) {
|
||||||
// some commands prints theirs output to stderr instead of stdout. 'javac' is the example
|
const dir = directories[i];
|
||||||
else d.resolve((catchStderr ? stderr : stdout).trim());
|
if (/^(jdk)+./.test(dir)) {
|
||||||
});
|
return path.resolve(directory, 'java', dir);
|
||||||
return d.promise;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.isWindows = function () {
|
module.exports.isWindows = function () {
|
||||||
@@ -60,31 +58,49 @@ module.exports.isDarwin = function () {
|
|||||||
return (os.platform() === 'darwin');
|
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
|
* @description 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
|
||||||
|
* @returns {string} The android target in format "android-${target}"
|
||||||
|
*/
|
||||||
module.exports.get_target = function () {
|
module.exports.get_target = function () {
|
||||||
function extractFromFile (filePath) {
|
const projectPropertiesPaths = [
|
||||||
var target = shelljs.grep(/\btarget=/, filePath);
|
path.join(REPO_ROOT, 'framework', 'project.properties'),
|
||||||
if (!target) {
|
path.join(PROJECT_ROOT, 'project.properties')
|
||||||
throw new Error('Could not find android target within: ' + filePath);
|
];
|
||||||
|
|
||||||
|
// Get the minimum required target API from the framework.
|
||||||
|
let target = projectPropertiesPaths.filter(filePath => fs.existsSync(filePath))
|
||||||
|
.map(filePath => createEditor(filePath).get('target'))
|
||||||
|
.pop();
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
throw new Error(`We could not locate the target from the "project.properties" at either "${projectPropertiesPaths.join('", "')}".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the repo config.xml file exists, find the desired targetSdkVersion.
|
||||||
|
const configFile = path.join(REPO_ROOT, 'config.xml');
|
||||||
|
if (!fs.existsSync(configFile)) return target;
|
||||||
|
|
||||||
|
const configParser = new ConfigParser(configFile);
|
||||||
|
const desiredAPI = parseInt(configParser.getPreference('android-targetSdkVersion', 'android'), 10);
|
||||||
|
|
||||||
|
if (!isNaN(desiredAPI)) {
|
||||||
|
const minimumAPI = parseInt(target.split('-').pop(), 10);
|
||||||
|
|
||||||
|
if (desiredAPI >= minimumAPI) {
|
||||||
|
target = `android-${desiredAPI}`;
|
||||||
|
} else {
|
||||||
|
events.emit('warn', `android-targetSdkVersion should be greater than or equal to ${minimumAPI}.`);
|
||||||
}
|
}
|
||||||
return target.split('=')[1].trim();
|
|
||||||
}
|
}
|
||||||
var repo_file = path.join(REPO_ROOT, 'framework', 'project.properties');
|
|
||||||
if (fs.existsSync(repo_file)) {
|
return target;
|
||||||
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.
|
// Returns a promise. Called only by build and clean commands.
|
||||||
module.exports.check_ant = function () {
|
module.exports.check_ant = function () {
|
||||||
return superspawn.spawn('ant', ['-version']).then(function (output) {
|
return execa('ant', ['-version']).then(({ stdout: output }) => {
|
||||||
// Parse Ant version from command output
|
// Parse Ant version from command output
|
||||||
return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
|
return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
@@ -101,19 +117,18 @@ module.exports.get_gradle_wrapper = function () {
|
|||||||
var program_dir;
|
var program_dir;
|
||||||
// OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually!
|
// OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually!
|
||||||
if (module.exports.isWindows()) {
|
if (module.exports.isWindows()) {
|
||||||
|
var result = execa.sync(path.join(__dirname, 'getASPath.bat'));
|
||||||
var result = child_process.spawnSync(path.join(__dirname, 'getASPath.bat'));
|
|
||||||
// console.log('result.stdout =' + result.stdout.toString());
|
// console.log('result.stdout =' + result.stdout.toString());
|
||||||
// console.log('result.stderr =' + result.stderr.toString());
|
// console.log('result.stderr =' + result.stderr.toString());
|
||||||
|
|
||||||
if (result.stderr.toString().length > 0) {
|
if (result.stderr.toString().length > 0) {
|
||||||
var androidPath = path.join(process.env['ProgramFiles'], 'Android') + '/';
|
var androidPath = path.join(process.env.ProgramFiles, 'Android') + '/';
|
||||||
if (fs.existsSync(androidPath)) {
|
if (fs.existsSync(androidPath)) {
|
||||||
program_dir = fs.readdirSync(androidPath);
|
program_dir = fs.readdirSync(androidPath);
|
||||||
while (i < program_dir.length && !foundStudio) {
|
while (i < program_dir.length && !foundStudio) {
|
||||||
if (program_dir[i].startsWith('Android Studio')) {
|
if (program_dir[i].startsWith('Android Studio')) {
|
||||||
foundStudio = true;
|
foundStudio = true;
|
||||||
androidStudioPath = path.join(process.env['ProgramFiles'], 'Android', program_dir[i], 'gradle');
|
androidStudioPath = path.join(process.env.ProgramFiles, 'Android', program_dir[i], 'gradle');
|
||||||
} else { ++i; }
|
} else { ++i; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,31 +153,30 @@ module.exports.get_gradle_wrapper = function () {
|
|||||||
|
|
||||||
// Returns a promise. Called only by build and clean commands.
|
// Returns a promise. Called only by build and clean commands.
|
||||||
module.exports.check_gradle = function () {
|
module.exports.check_gradle = function () {
|
||||||
var sdkDir = process.env['ANDROID_HOME'];
|
var sdkDir = process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME;
|
||||||
var d = Q.defer();
|
|
||||||
if (!sdkDir) {
|
if (!sdkDir) {
|
||||||
return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' +
|
return Promise.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.'));
|
'Might need to install Android SDK or set up \'ANDROID_SDK_ROOT\' env variable.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var gradlePath = module.exports.get_gradle_wrapper();
|
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' +
|
if (gradlePath.length !== 0) return Promise.resolve(gradlePath);
|
||||||
'or on your system to install the gradle wrapper. Please include gradle \n' +
|
|
||||||
'in your path, or install Android Studio'));
|
return Promise.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' +
|
||||||
return d.promise;
|
'in your path, or install Android Studio'));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
module.exports.check_java = function () {
|
module.exports.check_java = function () {
|
||||||
var javacPath = forgivingWhichSync('javac');
|
var javacPath = forgivingWhichSync('javac');
|
||||||
var hasJavaHome = !!process.env['JAVA_HOME'];
|
var hasJavaHome = !!process.env.JAVA_HOME;
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (hasJavaHome) {
|
if (hasJavaHome) {
|
||||||
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
|
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
|
||||||
if (!javacPath) {
|
if (!javacPath) {
|
||||||
process.env['PATH'] += path.delimiter + path.join(process.env['JAVA_HOME'], 'bin');
|
process.env.PATH += path.delimiter + path.join(process.env.JAVA_HOME, 'bin');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (javacPath) {
|
if (javacPath) {
|
||||||
@@ -170,8 +184,8 @@ module.exports.check_java = function () {
|
|||||||
var find_java = '/usr/libexec/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.';
|
var default_java_error_msg = 'Failed to find \'JAVA_HOME\' environment variable. Try setting it manually.';
|
||||||
if (fs.existsSync(find_java)) {
|
if (fs.existsSync(find_java)) {
|
||||||
return superspawn.spawn(find_java).then(function (stdout) {
|
return execa(find_java).then(({ stdout }) => {
|
||||||
process.env['JAVA_HOME'] = stdout.trim();
|
process.env.JAVA_HOME = stdout;
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new CordovaError(default_java_error_msg);
|
throw new CordovaError(default_java_error_msg);
|
||||||
@@ -179,93 +193,122 @@ module.exports.check_java = function () {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// See if we can derive it from javac's location.
|
// 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));
|
var maybeJavaHome = path.dirname(path.dirname(javacPath));
|
||||||
if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {
|
if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {
|
||||||
process.env['JAVA_HOME'] = maybeJavaHome;
|
process.env.JAVA_HOME = maybeJavaHome;
|
||||||
} else {
|
} else {
|
||||||
throw new CordovaError(default_java_error_msg);
|
throw new CordovaError(default_java_error_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (module.exports.isWindows()) {
|
} else if (module.exports.isWindows()) {
|
||||||
// Try to auto-detect java in the default install paths.
|
const programFilesEnv = path.resolve(process.env.ProgramFiles);
|
||||||
var oldSilent = shelljs.config.silent;
|
const programFiles = 'C:\\Program Files\\';
|
||||||
shelljs.config.silent = true;
|
const programFilesx86 = 'C:\\Program Files (x86)\\';
|
||||||
var firstJdkDir =
|
|
||||||
shelljs.ls(process.env['ProgramFiles'] + '\\java\\jdk*')[0] ||
|
let firstJdkDir =
|
||||||
shelljs.ls('C:\\Program Files\\java\\jdk*')[0] ||
|
getJDKDirectory(programFilesEnv) ||
|
||||||
shelljs.ls('C:\\Program Files (x86)\\java\\jdk*')[0];
|
getJDKDirectory(programFiles) ||
|
||||||
shelljs.config.silent = oldSilent;
|
getJDKDirectory(programFilesx86);
|
||||||
|
|
||||||
if (firstJdkDir) {
|
if (firstJdkDir) {
|
||||||
// shelljs always uses / in paths.
|
|
||||||
firstJdkDir = firstJdkDir.replace(/\//g, path.sep);
|
firstJdkDir = firstJdkDir.replace(/\//g, path.sep);
|
||||||
if (!javacPath) {
|
if (!javacPath) {
|
||||||
process.env['PATH'] += path.delimiter + path.join(firstJdkDir, 'bin');
|
process.env.PATH += path.delimiter + path.join(firstJdkDir, 'bin');
|
||||||
}
|
}
|
||||||
process.env['JAVA_HOME'] = firstJdkDir;
|
process.env.JAVA_HOME = firstJdkDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
var msg =
|
return execa('javac', ['-version'], { all: true })
|
||||||
'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
|
.then(({ all: output }) => {
|
||||||
'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
|
// Java <= 8 writes version info to stderr, Java >= 9 to stdout
|
||||||
if (process.env['JAVA_HOME']) {
|
const match = /javac\s+([\d.]+)/i.exec(output);
|
||||||
msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
|
return match && match[1];
|
||||||
}
|
}, () => {
|
||||||
// We use tryCommand with catchStderr = true, because
|
var msg =
|
||||||
// javac writes version info to stderr instead of stdout
|
'Failed to run "javac -version", make sure that you have a JDK version 8 installed.\n' +
|
||||||
return tryCommand('javac -version', msg, true).then(function (output) {
|
'You can get it from the following location:\n' +
|
||||||
// Let's check for at least Java 8, and keep it future proof so we can support Java 10
|
'https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html';
|
||||||
var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output);
|
if (process.env.JAVA_HOME) {
|
||||||
return match && match[1];
|
msg += '\n\n';
|
||||||
});
|
msg += 'Your JAVA_HOME is invalid: ' + process.env.JAVA_HOME;
|
||||||
|
}
|
||||||
|
throw new CordovaError(msg);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
module.exports.check_android = function () {
|
module.exports.check_android = function () {
|
||||||
return Q().then(function () {
|
return Promise.resolve().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) {
|
function maybeSetAndroidHome (value) {
|
||||||
if (!hasAndroidHome && fs.existsSync(value)) {
|
if (!hasAndroidHome && fs.existsSync(value)) {
|
||||||
hasAndroidHome = true;
|
hasAndroidHome = true;
|
||||||
process.env['ANDROID_HOME'] = value;
|
process.env.ANDROID_SDK_ROOT = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var androidCmdPath = forgivingWhichSync('android');
|
||||||
|
var adbInPath = forgivingWhichSync('adb');
|
||||||
|
var avdmanagerInPath = forgivingWhichSync('avdmanager');
|
||||||
|
var hasAndroidHome = false;
|
||||||
|
|
||||||
|
if (process.env.ANDROID_SDK_ROOT) {
|
||||||
|
maybeSetAndroidHome(path.resolve(process.env.ANDROID_SDK_ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
// First ensure ANDROID_HOME is set
|
// First ensure ANDROID_HOME is set
|
||||||
// If we have no hints (nothing in PATH), try a few default locations
|
// If we have no hints (nothing in PATH), try a few default locations
|
||||||
if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath) {
|
if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath) {
|
||||||
|
if (process.env.ANDROID_HOME) {
|
||||||
|
// Fallback to deprecated `ANDROID_HOME` variable
|
||||||
|
maybeSetAndroidHome(path.join(process.env.ANDROID_HOME));
|
||||||
|
}
|
||||||
if (module.exports.isWindows()) {
|
if (module.exports.isWindows()) {
|
||||||
// Android Studio 1.0 installer
|
// Android Studio 1.0 installer
|
||||||
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'sdk'));
|
if (process.env.LOCALAPPDATA) {
|
||||||
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'sdk'));
|
maybeSetAndroidHome(path.join(process.env.LOCALAPPDATA, 'Android', 'sdk'));
|
||||||
|
}
|
||||||
|
if (process.env.ProgramFiles) {
|
||||||
|
maybeSetAndroidHome(path.join(process.env.ProgramFiles, 'Android', 'sdk'));
|
||||||
|
}
|
||||||
|
|
||||||
// Android Studio pre-1.0 installer
|
// Android Studio pre-1.0 installer
|
||||||
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-studio', 'sdk'));
|
if (process.env.LOCALAPPDATA) {
|
||||||
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-studio', 'sdk'));
|
maybeSetAndroidHome(path.join(process.env.LOCALAPPDATA, 'Android', 'android-studio', 'sdk'));
|
||||||
|
}
|
||||||
|
if (process.env.ProgramFiles) {
|
||||||
|
maybeSetAndroidHome(path.join(process.env.ProgramFiles, 'Android', 'android-studio', 'sdk'));
|
||||||
|
}
|
||||||
|
|
||||||
// Stand-alone installer
|
// Stand-alone installer
|
||||||
maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-sdk'));
|
if (process.env.LOCALAPPDATA) {
|
||||||
maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-sdk'));
|
maybeSetAndroidHome(path.join(process.env.LOCALAPPDATA, 'Android', 'android-sdk'));
|
||||||
|
}
|
||||||
|
if (process.env.ProgramFiles) {
|
||||||
|
maybeSetAndroidHome(path.join(process.env.ProgramFiles, 'Android', 'android-sdk'));
|
||||||
|
}
|
||||||
} else if (module.exports.isDarwin()) {
|
} else if (module.exports.isDarwin()) {
|
||||||
// Android Studio 1.0 installer
|
// Android Studio 1.0 installer
|
||||||
maybeSetAndroidHome(path.join(process.env['HOME'], 'Library', 'Android', 'sdk'));
|
if (process.env.HOME) {
|
||||||
|
maybeSetAndroidHome(path.join(process.env.HOME, 'Library', 'Android', 'sdk'));
|
||||||
|
}
|
||||||
// Android Studio pre-1.0 installer
|
// Android Studio pre-1.0 installer
|
||||||
maybeSetAndroidHome('/Applications/Android Studio.app/sdk');
|
maybeSetAndroidHome('/Applications/Android Studio.app/sdk');
|
||||||
// Stand-alone zip file that user might think to put under /Applications
|
// Stand-alone zip file that user might think to put under /Applications
|
||||||
maybeSetAndroidHome('/Applications/android-sdk-macosx');
|
maybeSetAndroidHome('/Applications/android-sdk-macosx');
|
||||||
maybeSetAndroidHome('/Applications/android-sdk');
|
maybeSetAndroidHome('/Applications/android-sdk');
|
||||||
}
|
}
|
||||||
if (process.env['HOME']) {
|
if (process.env.HOME) {
|
||||||
// Stand-alone zip file that user might think to put under their home directory
|
// 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-macosx'));
|
||||||
maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk'));
|
maybeSetAndroidHome(path.join(process.env.HOME, 'android-sdk'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasAndroidHome) {
|
if (!hasAndroidHome) {
|
||||||
// If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to infer from the tooling PATH.
|
// If we dont have ANDROID_SDK_ROOT, but we do have some tools on the PATH, try to infer from the tooling PATH.
|
||||||
var parentDir, grandParentDir;
|
var parentDir, grandParentDir;
|
||||||
if (androidCmdPath) {
|
if (androidCmdPath) {
|
||||||
parentDir = path.dirname(androidCmdPath);
|
parentDir = path.dirname(androidCmdPath);
|
||||||
@@ -273,7 +316,7 @@ module.exports.check_android = function () {
|
|||||||
if (path.basename(parentDir) === 'tools' || fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
|
if (path.basename(parentDir) === 'tools' || fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
|
||||||
maybeSetAndroidHome(grandParentDir);
|
maybeSetAndroidHome(grandParentDir);
|
||||||
} else {
|
} else {
|
||||||
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
throw new CordovaError('Failed to find \'ANDROID_SDK_ROOT\' environment variable. Try setting it manually.\n' +
|
||||||
'Detected \'android\' command at ' + parentDir + ' but no \'tools\' directory found near.\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.');
|
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools directory.');
|
||||||
}
|
}
|
||||||
@@ -284,7 +327,7 @@ module.exports.check_android = function () {
|
|||||||
if (path.basename(parentDir) === 'platform-tools') {
|
if (path.basename(parentDir) === 'platform-tools') {
|
||||||
maybeSetAndroidHome(grandParentDir);
|
maybeSetAndroidHome(grandParentDir);
|
||||||
} else {
|
} else {
|
||||||
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
throw new CordovaError('Failed to find \'ANDROID_SDK_ROOT\' environment variable. Try setting it manually.\n' +
|
||||||
'Detected \'adb\' command at ' + parentDir + ' but no \'platform-tools\' directory found near.\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.');
|
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'platform-tools directory.');
|
||||||
}
|
}
|
||||||
@@ -295,29 +338,29 @@ module.exports.check_android = function () {
|
|||||||
if (path.basename(parentDir) === 'bin' && path.basename(grandParentDir) === 'tools') {
|
if (path.basename(parentDir) === 'bin' && path.basename(grandParentDir) === 'tools') {
|
||||||
maybeSetAndroidHome(path.dirname(grandParentDir));
|
maybeSetAndroidHome(path.dirname(grandParentDir));
|
||||||
} else {
|
} else {
|
||||||
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
throw new CordovaError('Failed to find \'ANDROID_SDK_ROOT\' environment variable. Try setting it manually.\n' +
|
||||||
'Detected \'avdmanager\' command at ' + parentDir + ' but no \'tools' + path.sep + 'bin\' directory found near.\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.');
|
'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']) {
|
if (!process.env.ANDROID_SDK_ROOT) {
|
||||||
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
throw new CordovaError('Failed to find \'ANDROID_SDK_ROOT\' 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.');
|
'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'])) {
|
if (!fs.existsSync(process.env.ANDROID_SDK_ROOT)) {
|
||||||
throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent path: ' + process.env['ANDROID_HOME'] +
|
throw new CordovaError('\'ANDROID_SDK_ROOT\' environment variable is set to non-existent path: ' + process.env.ANDROID_SDK_ROOT +
|
||||||
'\nTry update it manually to point to valid SDK directory.');
|
'\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
|
// Next let's make sure relevant parts of the SDK tooling is in our PATH
|
||||||
if (hasAndroidHome && !androidCmdPath) {
|
if (hasAndroidHome && !androidCmdPath) {
|
||||||
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools');
|
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_SDK_ROOT, 'tools');
|
||||||
}
|
}
|
||||||
if (hasAndroidHome && !adbInPath) {
|
if (hasAndroidHome && !adbInPath) {
|
||||||
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'platform-tools');
|
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_SDK_ROOT, 'platform-tools');
|
||||||
}
|
}
|
||||||
if (hasAndroidHome && !avdmanagerInPath) {
|
if (hasAndroidHome && !avdmanagerInPath) {
|
||||||
process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools', 'bin');
|
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_SDK_ROOT, 'tools', 'bin');
|
||||||
}
|
}
|
||||||
return hasAndroidHome;
|
return hasAndroidHome;
|
||||||
});
|
});
|
||||||
@@ -362,16 +405,22 @@ module.exports.check_android_target = function (originalError) {
|
|||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
module.exports.run = function () {
|
module.exports.run = function () {
|
||||||
return Q.all([this.check_java(), this.check_android()]).then(function (values) {
|
console.log('Checking Java JDK and Android SDK versions');
|
||||||
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
|
console.log('ANDROID_SDK_ROOT=' + process.env.ANDROID_SDK_ROOT + ' (recommended setting)');
|
||||||
console.log('JAVA_HOME=' + process.env['JAVA_HOME']);
|
console.log('ANDROID_HOME=' + process.env.ANDROID_HOME + ' (DEPRECATED)');
|
||||||
|
|
||||||
if (!values[0]) {
|
return Promise.all([this.check_java(), this.check_android()]).then(function (values) {
|
||||||
throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
|
console.log('Using Android SDK: ' + process.env.ANDROID_SDK_ROOT);
|
||||||
|
|
||||||
|
if (!String(values[0]).startsWith('1.8.')) {
|
||||||
|
throw new CordovaError(
|
||||||
|
'Requirements check failed for JDK 8 (\'1.8.*\')! Detected version: ' + values[0] + '\n' +
|
||||||
|
'Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!values[1]) {
|
if (!values[1]) {
|
||||||
throw new CordovaError('Requirements check failed for Android SDK');
|
throw new CordovaError('Requirements check failed for Android SDK! Android SDK was not detected.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -400,7 +449,6 @@ var Requirement = function (id, name, version, installed) {
|
|||||||
* @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
|
* @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
|
||||||
*/
|
*/
|
||||||
module.exports.check_all = function () {
|
module.exports.check_all = function () {
|
||||||
|
|
||||||
var requirements = [
|
var requirements = [
|
||||||
new Requirement('java', 'Java JDK'),
|
new Requirement('java', 'Java JDK'),
|
||||||
new Requirement('androidSdk', 'Android SDK'),
|
new Requirement('androidSdk', 'Android SDK'),
|
||||||
@@ -425,7 +473,7 @@ module.exports.check_all = function () {
|
|||||||
}, function (err) {
|
}, function (err) {
|
||||||
requirement.metadata.reason = err instanceof Error ? err.message : err;
|
requirement.metadata.reason = err instanceof Error ? err.message : err;
|
||||||
});
|
});
|
||||||
}, Q()).then(function () {
|
}, Promise.resolve()).then(function () {
|
||||||
// When chain is completed, return requirements array to upstream API
|
// When chain is completed, return requirements array to upstream API
|
||||||
return requirements;
|
return requirements;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/**
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const propertiesParser = require('properties-parser');
|
||||||
|
const events = require('cordova-common').events;
|
||||||
|
|
||||||
|
class GradlePropertiesParser {
|
||||||
|
/**
|
||||||
|
* Loads and Edits Gradle Properties File.
|
||||||
|
*
|
||||||
|
* @param {String} platformDir is the path of the Android platform directory
|
||||||
|
*/
|
||||||
|
constructor (platformDir) {
|
||||||
|
this._defaults = {
|
||||||
|
// 10 seconds -> 6 seconds
|
||||||
|
'org.gradle.daemon': 'true',
|
||||||
|
|
||||||
|
// to allow dex in process
|
||||||
|
'org.gradle.jvmargs': '-Xmx2048m',
|
||||||
|
|
||||||
|
// Android X
|
||||||
|
'android.useAndroidX': 'false',
|
||||||
|
'android.enableJetifier': 'false'
|
||||||
|
|
||||||
|
// Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
|
||||||
|
// 'org.gradle.parallel': 'true'
|
||||||
|
};
|
||||||
|
|
||||||
|
this.gradleFilePath = path.join(platformDir, 'gradle.properties');
|
||||||
|
}
|
||||||
|
|
||||||
|
configure (userConfigs) {
|
||||||
|
events.emit('verbose', '[Gradle Properties] Preparing Configuration');
|
||||||
|
|
||||||
|
this._initializeEditor();
|
||||||
|
|
||||||
|
events.emit('verbose', '[Gradle Properties] Appending default configuration properties');
|
||||||
|
this._configureProperties(this._defaults);
|
||||||
|
|
||||||
|
events.emit('verbose', '[Gradle Properties] Appending custom configuration properties');
|
||||||
|
this._configureProperties(userConfigs);
|
||||||
|
|
||||||
|
this._save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the properties editor for parsing, setting, etc.
|
||||||
|
*/
|
||||||
|
_initializeEditor () {
|
||||||
|
// Touch empty gradle.properties file if missing.
|
||||||
|
if (!fs.existsSync(this.gradleFilePath)) {
|
||||||
|
events.emit('verbose', '[Gradle Properties] File missing, creating file with Cordova defaults.');
|
||||||
|
fs.writeFileSync(this.gradleFilePath, '', 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an editor for parsing, getting, and setting configurations.
|
||||||
|
this.gradleFile = propertiesParser.createEditor(this.gradleFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that defaults or user configuration properties are set and
|
||||||
|
* set the missing items.
|
||||||
|
*/
|
||||||
|
_configureProperties (properties) {
|
||||||
|
// Iterate though the properties and set only if missing.
|
||||||
|
Object.keys(properties).forEach(key => {
|
||||||
|
const value = this.gradleFile.get(key);
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
// Handles the case of adding missing defaults or new properties that are missing.
|
||||||
|
events.emit('verbose', `[Gradle Properties] Appending configuration item: ${key}=${properties[key]}`);
|
||||||
|
this.gradleFile.set(key, properties[key]);
|
||||||
|
} else if (value !== properties[key]) {
|
||||||
|
if (this._defaults[key] && this._defaults[key] !== properties[key]) {
|
||||||
|
let shouldEmit = true;
|
||||||
|
if (key === 'org.gradle.jvmargs') {
|
||||||
|
shouldEmit = this._isJVMMemoryLessThanRecommended(properties[key], this._defaults[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldEmit) {
|
||||||
|
// Since the value does not match default, we will notify the discrepancy with Cordova's recommended value.
|
||||||
|
events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${properties[key]}", Cordova's recommended value is "${this._defaults[key]}"`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// When the current value exists but does not match the new value or does matches the default key value, the new value it set.
|
||||||
|
events.emit('verbose', `[Gradle Properties] Updating Gradle property "${key}" with the value of "${properties[key]}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We will set the new value in either case.
|
||||||
|
this.gradleFile.set(key, properties[key]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_isJVMMemoryLessThanRecommended (memoryValue, recommendedMemoryValue) {
|
||||||
|
const UNIT = 2;
|
||||||
|
const SIZE = 1;
|
||||||
|
const regex = /-Xmx+([0-9]+)+([mMgGkK])/;
|
||||||
|
|
||||||
|
const recommendedCapture = regex.exec(recommendedMemoryValue);
|
||||||
|
const recommendedBase = this._getBaseJVMSize(recommendedCapture[SIZE], recommendedCapture[UNIT]);
|
||||||
|
const memoryCapture = regex.exec(memoryValue);
|
||||||
|
const memoryBase = this._getBaseJVMSize(memoryCapture[SIZE], memoryCapture[UNIT]);
|
||||||
|
|
||||||
|
return memoryBase < recommendedBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getBaseJVMSize (size, unit) {
|
||||||
|
const KILOBYTE = 1024;
|
||||||
|
const MEGABYTE = 1048576;
|
||||||
|
const GIGABYTE = 1073741824;
|
||||||
|
|
||||||
|
switch (unit.toLowerCase()) {
|
||||||
|
case 'k': return size * KILOBYTE;
|
||||||
|
case 'm': return size * MEGABYTE;
|
||||||
|
case 'g': return size * GIGABYTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
events.emit('warn', `[Gradle Properties] Unknown memory size unit (${unit})`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves any changes that has been made to the properties file.
|
||||||
|
*/
|
||||||
|
_save () {
|
||||||
|
events.emit('verbose', '[Gradle Properties] Updating and Saving File');
|
||||||
|
this.gradleFile.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = GradlePropertiesParser;
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,12 +17,11 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Q = require('q');
|
const execa = require('execa');
|
||||||
var build = require('./build');
|
var build = require('./build');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Adb = require('./Adb');
|
var Adb = require('./Adb');
|
||||||
var AndroidManifest = require('./AndroidManifest');
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
var spawn = require('cordova-common').superspawn.spawn;
|
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
|
|
||||||
@@ -38,7 +35,7 @@ module.exports.list = function (lookHarder) {
|
|||||||
// adb kill-server doesn't seem to do the trick.
|
// adb kill-server doesn't seem to do the trick.
|
||||||
// Could probably find a x-platform version of killall, but I'm not actually
|
// Could probably find a x-platform version of killall, but I'm not actually
|
||||||
// sure that this scenario even happens on non-OSX machines.
|
// sure that this scenario even happens on non-OSX machines.
|
||||||
return spawn('killall', ['adb']).then(function () {
|
return execa('killall', ['adb']).then(function () {
|
||||||
events.emit('verbose', 'Restarting adb to see if more devices are detected.');
|
events.emit('verbose', 'Restarting adb to see if more devices are detected.');
|
||||||
return Adb.devices();
|
return Adb.devices();
|
||||||
}, function () {
|
}, function () {
|
||||||
@@ -53,13 +50,13 @@ module.exports.list = function (lookHarder) {
|
|||||||
module.exports.resolveTarget = function (target) {
|
module.exports.resolveTarget = function (target) {
|
||||||
return this.list(true).then(function (device_list) {
|
return this.list(true).then(function (device_list) {
|
||||||
if (!device_list || !device_list.length) {
|
if (!device_list || !device_list.length) {
|
||||||
return Q.reject(new CordovaError('Failed to deploy to device, no devices found.'));
|
return Promise.reject(new CordovaError('Failed to deploy to device, no devices found.'));
|
||||||
}
|
}
|
||||||
// default device
|
// default device
|
||||||
target = target || device_list[0];
|
target = target || device_list[0];
|
||||||
|
|
||||||
if (device_list.indexOf(target) < 0) {
|
if (device_list.indexOf(target) < 0) {
|
||||||
return Q.reject('ERROR: Unable to find target \'' + target + '\'.');
|
return Promise.reject(new CordovaError('ERROR: Unable to find target \'' + target + '\'.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return build.detectArchitecture(target).then(function (arch) {
|
return build.detectArchitecture(target).then(function (arch) {
|
||||||
@@ -74,7 +71,7 @@ module.exports.resolveTarget = function (target) {
|
|||||||
* Returns a promise.
|
* Returns a promise.
|
||||||
*/
|
*/
|
||||||
module.exports.install = function (target, buildResults) {
|
module.exports.install = function (target, buildResults) {
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (target && typeof target === 'object') {
|
if (target && typeof target === 'object') {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@@ -87,7 +84,7 @@ module.exports.install = function (target, buildResults) {
|
|||||||
events.emit('log', 'Using apk: ' + apk_path);
|
events.emit('log', 'Using apk: ' + apk_path);
|
||||||
events.emit('log', 'Package name: ' + pkgName);
|
events.emit('log', 'Package name: ' + pkgName);
|
||||||
|
|
||||||
return Adb.install(resolvedTarget.target, apk_path, {replace: true}).catch(function (error) {
|
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
|
// CB-9557 CB-10157 only uninstall and reinstall app if the one that
|
||||||
// is already installed on device was signed w/different certificate
|
// is already installed on device was signed w/different certificate
|
||||||
if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString())) { throw error; }
|
if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString())) { throw error; }
|
||||||
@@ -98,7 +95,7 @@ module.exports.install = function (target, buildResults) {
|
|||||||
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
// 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.
|
// or the app doesn't installed at all, so no error catching needed.
|
||||||
return Adb.uninstall(resolvedTarget.target, pkgName).then(function () {
|
return Adb.uninstall(resolvedTarget.target, pkgName).then(function () {
|
||||||
return Adb.install(resolvedTarget.target, apk_path, {replace: true});
|
return Adb.install(resolvedTarget.target, apk_path, { replace: true });
|
||||||
});
|
});
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// unlock screen
|
// unlock screen
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,8 +17,8 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint sub:true */
|
const execa = require('execa');
|
||||||
|
const fs = require('fs-extra');
|
||||||
var android_versions = require('android-versions');
|
var android_versions = require('android-versions');
|
||||||
var retry = require('./retry');
|
var retry = require('./retry');
|
||||||
var build = require('./build');
|
var build = require('./build');
|
||||||
@@ -28,54 +26,49 @@ var path = require('path');
|
|||||||
var Adb = require('./Adb');
|
var Adb = require('./Adb');
|
||||||
var AndroidManifest = require('./AndroidManifest');
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
var superspawn = require('cordova-common').superspawn;
|
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
var shelljs = require('shelljs');
|
|
||||||
var android_sdk = require('./android_sdk');
|
var android_sdk = require('./android_sdk');
|
||||||
var check_reqs = require('./check_reqs');
|
var check_reqs = require('./check_reqs');
|
||||||
|
var which = require('which');
|
||||||
var Q = require('q');
|
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var fs = require('fs');
|
|
||||||
var child_process = require('child_process');
|
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
var ONE_SECOND = 1000; // in milliseconds
|
const ONE_SECOND = 1000; // in milliseconds
|
||||||
var ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
|
const ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
|
||||||
var INSTALL_COMMAND_TIMEOUT = 5 * ONE_MINUTE; // in milliseconds
|
const INSTALL_COMMAND_TIMEOUT = 5 * ONE_MINUTE; // in milliseconds
|
||||||
var NUM_INSTALL_RETRIES = 3;
|
const NUM_INSTALL_RETRIES = 3;
|
||||||
var CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds
|
const CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds
|
||||||
var EXEC_KILL_SIGNAL = 'SIGKILL';
|
const EXEC_KILL_SIGNAL = 'SIGKILL';
|
||||||
|
|
||||||
function forgivingWhichSync (cmd) {
|
function forgivingWhichSync (cmd) {
|
||||||
try {
|
const whichResult = which.sync(cmd, { nothrow: true });
|
||||||
return fs.realpathSync(shelljs.which(cmd));
|
|
||||||
} catch (e) {
|
// On null, returns empty string to maintain backwards compatibility
|
||||||
return '';
|
// realpathSync follows symlinks
|
||||||
}
|
return whichResult === null ? '' : fs.realpathSync(whichResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.list_images_using_avdmanager = function () {
|
module.exports.list_images_using_avdmanager = function () {
|
||||||
return superspawn.spawn('avdmanager', ['list', 'avd']).then(function (output) {
|
return execa('avdmanager', ['list', 'avd']).then(({ stdout: output }) => {
|
||||||
var response = output.split('\n');
|
var response = output.split('\n');
|
||||||
var emulator_list = [];
|
var emulator_list = [];
|
||||||
for (var i = 1; i < response.length; i++) {
|
for (var i = 1; i < response.length; i++) {
|
||||||
// To return more detailed information use img_obj
|
// To return more detailed information use img_obj
|
||||||
var img_obj = {};
|
var img_obj = {};
|
||||||
if (response[i].match(/Name:\s/)) {
|
if (response[i].match(/Name:\s/)) {
|
||||||
img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
|
img_obj.name = response[i].split('Name: ')[1].replace('\r', '');
|
||||||
if (response[i + 1].match(/Device:\s/)) {
|
if (response[i + 1].match(/Device:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
|
img_obj.device = response[i].split('Device: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/Path:\s/)) {
|
if (response[i + 1].match(/Path:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
|
img_obj.path = response[i].split('Path: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/Target:\s/)) {
|
if (response[i + 1].match(/Target:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
if (response[i + 1].match(/ABI:\s/)) {
|
if (response[i + 1].match(/ABI:\s/)) {
|
||||||
img_obj['abi'] = response[i + 1].split('ABI: ')[1].replace('\r', '');
|
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`
|
// 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
|
// We do so so that we don't have to change the logic when parsing for the
|
||||||
@@ -83,24 +76,24 @@ module.exports.list_images_using_avdmanager = function () {
|
|||||||
// This allows us to transitionally support both `android` and `avdmanager` binaries,
|
// This allows us to transitionally support both `android` and `avdmanager` binaries,
|
||||||
// depending on what SDK version the user has
|
// depending on what SDK version the user has
|
||||||
if (response[i + 1].match(/Based\son:\s/)) {
|
if (response[i + 1].match(/Based\son:\s/)) {
|
||||||
img_obj['target'] = response[i + 1].split('Based on:')[1];
|
img_obj.target = response[i + 1].split('Based on:')[1];
|
||||||
if (img_obj['target'].match(/Tag\/ABI:\s/)) {
|
if (img_obj.target.match(/Tag\/ABI:\s/)) {
|
||||||
img_obj['target'] = img_obj['target'].split('Tag/ABI:')[0].replace('\r', '').trim();
|
img_obj.target = img_obj.target.split('Tag/ABI:')[0].replace('\r', '').trim();
|
||||||
if (img_obj['target'].indexOf('(') > -1) {
|
if (img_obj.target.indexOf('(') > -1) {
|
||||||
img_obj['target'] = img_obj['target'].substr(0, img_obj['target'].indexOf('(') - 1).trim();
|
img_obj.target = img_obj.target.substr(0, img_obj.target.indexOf('(') - 1).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var version_string = img_obj['target'].replace(/Android\s+/, '');
|
var version_string = img_obj.target.replace(/Android\s+/, '');
|
||||||
|
|
||||||
var api_level = android_sdk.version_string_to_api_level[version_string];
|
var api_level = android_sdk.version_string_to_api_level[version_string];
|
||||||
if (api_level) {
|
if (api_level) {
|
||||||
img_obj['target'] += ' (API level ' + api_level + ')';
|
img_obj.target += ' (API level ' + api_level + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/Skin:\s/)) {
|
if (response[i + 1].match(/Skin:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
|
img_obj.skin = response[i].split('Skin: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
emulator_list.push(img_obj);
|
emulator_list.push(img_obj);
|
||||||
@@ -109,41 +102,40 @@ module.exports.list_images_using_avdmanager = function () {
|
|||||||
if (response[i].match(/Name:\s/)) {
|
if (response[i].match(/Name:\s/)) {
|
||||||
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
||||||
} */
|
} */
|
||||||
|
|
||||||
}
|
}
|
||||||
return emulator_list;
|
return emulator_list;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.list_images_using_android = function () {
|
module.exports.list_images_using_android = function () {
|
||||||
return superspawn.spawn('android', ['list', 'avd']).then(function (output) {
|
return execa('android', ['list', 'avd']).then(({ stdout: output }) => {
|
||||||
var response = output.split('\n');
|
var response = output.split('\n');
|
||||||
var emulator_list = [];
|
var emulator_list = [];
|
||||||
for (var i = 1; i < response.length; i++) {
|
for (var i = 1; i < response.length; i++) {
|
||||||
// To return more detailed information use img_obj
|
// To return more detailed information use img_obj
|
||||||
var img_obj = {};
|
var img_obj = {};
|
||||||
if (response[i].match(/Name:\s/)) {
|
if (response[i].match(/Name:\s/)) {
|
||||||
img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
|
img_obj.name = response[i].split('Name: ')[1].replace('\r', '');
|
||||||
if (response[i + 1].match(/Device:\s/)) {
|
if (response[i + 1].match(/Device:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
|
img_obj.device = response[i].split('Device: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/Path:\s/)) {
|
if (response[i + 1].match(/Path:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
|
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/))) {
|
if (response[i + 1].match(/\(API\slevel\s/) || (response[i + 2] && response[i + 2].match(/\(API\slevel\s/))) {
|
||||||
i++;
|
i++;
|
||||||
var secondLine = response[i + 1].match(/\(API\slevel\s/) ? response[i + 1] : '';
|
var secondLine = response[i + 1].match(/\(API\slevel\s/) ? response[i + 1] : '';
|
||||||
img_obj['target'] = (response[i] + secondLine).split('Target: ')[1].replace('\r', '');
|
img_obj.target = (response[i] + secondLine).split('Target: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/ABI:\s/)) {
|
if (response[i + 1].match(/ABI:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['abi'] = response[i].split('ABI: ')[1].replace('\r', '');
|
img_obj.abi = response[i].split('ABI: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
if (response[i + 1].match(/Skin:\s/)) {
|
if (response[i + 1].match(/Skin:\s/)) {
|
||||||
i++;
|
i++;
|
||||||
img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
|
img_obj.skin = response[i].split('Skin: ')[1].replace('\r', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
emulator_list.push(img_obj);
|
emulator_list.push(img_obj);
|
||||||
@@ -152,7 +144,6 @@ module.exports.list_images_using_android = function () {
|
|||||||
if (response[i].match(/Name:\s/)) {
|
if (response[i].match(/Name:\s/)) {
|
||||||
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
|
||||||
} */
|
} */
|
||||||
|
|
||||||
}
|
}
|
||||||
return emulator_list;
|
return emulator_list;
|
||||||
});
|
});
|
||||||
@@ -170,15 +161,13 @@ module.exports.list_images_using_android = function () {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
module.exports.list_images = function () {
|
module.exports.list_images = function () {
|
||||||
return Q.fcall(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (forgivingWhichSync('avdmanager')) {
|
if (forgivingWhichSync('avdmanager')) {
|
||||||
return module.exports.list_images_using_avdmanager();
|
return module.exports.list_images_using_avdmanager();
|
||||||
} else if (forgivingWhichSync('android')) {
|
} else if (forgivingWhichSync('android')) {
|
||||||
return module.exports.list_images_using_android();
|
return module.exports.list_images_using_android();
|
||||||
} else {
|
} else {
|
||||||
return Q().then(function () {
|
return Promise.reject(new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?'));
|
||||||
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) {
|
}).then(function (avds) {
|
||||||
// In case we're missing the Android OS version string from the target description, add it.
|
// In case we're missing the Android OS version string from the target description, add it.
|
||||||
@@ -228,13 +217,13 @@ module.exports.best_image = function () {
|
|||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
module.exports.list_started = function () {
|
module.exports.list_started = function () {
|
||||||
return Adb.devices({emulators: true});
|
return Adb.devices({ emulators: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a promise.
|
// Returns a promise.
|
||||||
// TODO: we should remove this, there's a more robust method under android_sdk.js
|
// TODO: we should remove this, there's a more robust method under android_sdk.js
|
||||||
module.exports.list_targets = function () {
|
module.exports.list_targets = function () {
|
||||||
return superspawn.spawn('android', ['list', 'targets'], {cwd: os.tmpdir()}).then(function (output) {
|
return execa('android', ['list', 'targets'], { cwd: os.tmpdir() }).then(({ stdout: output }) => {
|
||||||
var target_out = output.split('\n');
|
var target_out = output.split('\n');
|
||||||
var targets = [];
|
var targets = [];
|
||||||
for (var i = target_out.length; i >= 0; i--) {
|
for (var i = target_out.length; i >= 0; i--) {
|
||||||
@@ -277,8 +266,8 @@ module.exports.get_available_port = function () {
|
|||||||
module.exports.start = function (emulator_ID, boot_timeout) {
|
module.exports.start = function (emulator_ID, boot_timeout) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (emulator_ID) return Q(emulator_ID);
|
if (emulator_ID) return Promise.resolve(emulator_ID);
|
||||||
|
|
||||||
return self.best_image().then(function (best) {
|
return self.best_image().then(function (best) {
|
||||||
if (best && best.name) {
|
if (best && best.name) {
|
||||||
@@ -287,7 +276,7 @@ module.exports.start = function (emulator_ID, boot_timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var androidCmd = check_reqs.getAbsoluteAndroidCmd();
|
var androidCmd = check_reqs.getAbsoluteAndroidCmd();
|
||||||
return Q.reject(new CordovaError('No emulator images (avds) found.\n' +
|
return Promise.reject(new CordovaError('No emulator images (avds) found.\n' +
|
||||||
'1. Download desired System Image by running: ' + androidCmd + ' sdk\n' +
|
'1. Download desired System Image by running: ' + androidCmd + ' sdk\n' +
|
||||||
'2. Create an AVD by running: ' + androidCmd + ' avd\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'));
|
'HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver\n'));
|
||||||
@@ -296,11 +285,10 @@ module.exports.start = function (emulator_ID, boot_timeout) {
|
|||||||
return self.get_available_port().then(function (port) {
|
return self.get_available_port().then(function (port) {
|
||||||
// Figure out the directory the emulator binary runs in, and set the cwd to that directory.
|
// 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
|
// Workaround for https://code.google.com/p/android/issues/detail?id=235461
|
||||||
var emulator_dir = path.dirname(shelljs.which('emulator'));
|
var emulator_dir = path.dirname(which.sync('emulator'));
|
||||||
var args = ['-avd', emulatorId, '-port', port];
|
var args = ['-avd', emulatorId, '-port', port];
|
||||||
// Don't wait for it to finish, since the emulator will probably keep running for a long time.
|
// Don't wait for it to finish, since the emulator will probably keep running for a long time.
|
||||||
child_process
|
execa('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
|
||||||
.spawn('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
|
|
||||||
.unref();
|
.unref();
|
||||||
|
|
||||||
// wait for emulator to start
|
// wait for emulator to start
|
||||||
@@ -308,7 +296,7 @@ module.exports.start = function (emulator_ID, boot_timeout) {
|
|||||||
return self.wait_for_emulator(port);
|
return self.wait_for_emulator(port);
|
||||||
});
|
});
|
||||||
}).then(function (emulatorId) {
|
}).then(function (emulatorId) {
|
||||||
if (!emulatorId) { return Q.reject(new CordovaError('Failed to start emulator')); }
|
if (!emulatorId) { return Promise.reject(new CordovaError('Failed to start emulator')); }
|
||||||
|
|
||||||
// wait for emulator to boot up
|
// wait for emulator to boot up
|
||||||
process.stdout.write('Waiting for emulator to boot (this may take a while)...');
|
process.stdout.write('Waiting for emulator to boot (this may take a while)...');
|
||||||
@@ -334,7 +322,7 @@ module.exports.start = function (emulator_ID, boot_timeout) {
|
|||||||
*/
|
*/
|
||||||
module.exports.wait_for_emulator = function (port) {
|
module.exports.wait_for_emulator = function (port) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
var emulator_id = 'emulator-' + port;
|
var emulator_id = 'emulator-' + port;
|
||||||
return Adb.shell(emulator_id, 'getprop dev.bootcomplete').then(function (output) {
|
return Adb.shell(emulator_id, 'getprop dev.bootcomplete').then(function (output) {
|
||||||
if (output.indexOf('1') >= 0) {
|
if (output.indexOf('1') >= 0) {
|
||||||
@@ -344,7 +332,9 @@ module.exports.wait_for_emulator = function (port) {
|
|||||||
}, function (error) {
|
}, function (error) {
|
||||||
if ((error && error.message &&
|
if ((error && error.message &&
|
||||||
(error.message.indexOf('not found') > -1)) ||
|
(error.message.indexOf('not found') > -1)) ||
|
||||||
(error.message.indexOf('device offline') > -1)) {
|
(error.message.indexOf('device offline') > -1) ||
|
||||||
|
(error.message.indexOf('device still connecting') > -1) ||
|
||||||
|
(error.message.indexOf('device still authorizing') > -1)) {
|
||||||
// emulator not yet started, continue waiting
|
// emulator not yet started, continue waiting
|
||||||
return self.wait_for_emulator(port);
|
return self.wait_for_emulator(port);
|
||||||
} else {
|
} else {
|
||||||
@@ -362,18 +352,21 @@ module.exports.wait_for_emulator = function (port) {
|
|||||||
*/
|
*/
|
||||||
module.exports.wait_for_boot = function (emulator_id, time_remaining) {
|
module.exports.wait_for_boot = function (emulator_id, time_remaining) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Adb.shell(emulator_id, 'ps').then(function (output) {
|
return Adb.shell(emulator_id, 'getprop sys.boot_completed').then(function (output) {
|
||||||
if (output.match(/android\.process\.acore/)) {
|
if (output.match(/1/)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (time_remaining === 0) {
|
} else if (time_remaining === 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
process.stdout.write('.');
|
process.stdout.write('.');
|
||||||
|
|
||||||
// Check at regular intervals
|
return new Promise(resolve => {
|
||||||
return Q.delay(time_remaining < CHECK_BOOTED_INTERVAL ? time_remaining : CHECK_BOOTED_INTERVAL).then(function () {
|
const delay = time_remaining < CHECK_BOOTED_INTERVAL ? time_remaining : CHECK_BOOTED_INTERVAL;
|
||||||
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);
|
setTimeout(() => {
|
||||||
|
const updated_time = time_remaining >= 0 ? Math.max(time_remaining - CHECK_BOOTED_INTERVAL, 0) : time_remaining;
|
||||||
|
resolve(self.wait_for_boot(emulator_id, updated_time));
|
||||||
|
}, delay);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -387,22 +380,22 @@ module.exports.wait_for_boot = function (emulator_id, time_remaining) {
|
|||||||
module.exports.create_image = function (name, target) {
|
module.exports.create_image = function (name, target) {
|
||||||
console.log('Creating new avd named ' + name);
|
console.log('Creating new avd named ' + name);
|
||||||
if (target) {
|
if (target) {
|
||||||
return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', target]).then(null, function (error) {
|
return execa('android', ['create', 'avd', '--name', name, '--target', target]).then(null, function (error) {
|
||||||
console.error('ERROR : Failed to create emulator image : ');
|
console.error('ERROR : Failed to create emulator image : ');
|
||||||
console.error(' Do you have the latest android targets including ' + target + '?');
|
console.error(' Do you have the latest android targets including ' + target + '?');
|
||||||
console.error(error);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.');
|
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
|
// 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 () {
|
return execa('android', ['create', 'avd', '--name', name, '--target', this.list_targets()[0]]).then(function () {
|
||||||
// TODO: This seems like another error case, even though it always happens.
|
// 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('ERROR : Unable to create an avd emulator, no targets found.');
|
||||||
console.error('Ensure you have targets available by running the "android" command');
|
console.error('Ensure you have targets available by running the "android" command');
|
||||||
return Q.reject();
|
return Promise.reject(new CordovaError());
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
console.error('ERROR : Failed to create emulator image : ');
|
console.error('ERROR : Failed to create emulator image : ');
|
||||||
console.error(error);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -410,17 +403,17 @@ module.exports.create_image = function (name, target) {
|
|||||||
module.exports.resolveTarget = function (target) {
|
module.exports.resolveTarget = function (target) {
|
||||||
return this.list_started().then(function (emulator_list) {
|
return this.list_started().then(function (emulator_list) {
|
||||||
if (emulator_list.length < 1) {
|
if (emulator_list.length < 1) {
|
||||||
return Q.reject('No running Android emulators found, please start an emulator before deploying your project.');
|
return Promise.reject(new CordovaError('No running Android emulators found, please start an emulator before deploying your project.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// default emulator
|
// default emulator
|
||||||
target = target || emulator_list[0];
|
target = target || emulator_list[0];
|
||||||
if (emulator_list.indexOf(target) < 0) {
|
if (emulator_list.indexOf(target) < 0) {
|
||||||
return Q.reject('Unable to find target \'' + target + '\'. Failed to deploy to emulator.');
|
return Promise.reject(new CordovaError('Unable to find target \'' + target + '\'. Failed to deploy to emulator.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return build.detectArchitecture(target).then(function (arch) {
|
return build.detectArchitecture(target).then(function (arch) {
|
||||||
return {target: target, arch: arch, isEmulator: true};
|
return { target: target, arch: arch, isEmulator: true };
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -432,18 +425,14 @@ module.exports.resolveTarget = function (target) {
|
|||||||
* Returns a promise.
|
* Returns a promise.
|
||||||
*/
|
*/
|
||||||
module.exports.install = function (givenTarget, buildResults) {
|
module.exports.install = function (givenTarget, buildResults) {
|
||||||
|
|
||||||
var target;
|
var target;
|
||||||
// We need to find the proper path to the Android Manifest
|
// We need to find the proper path to the Android Manifest
|
||||||
var manifestPath = path.join(__dirname, '..', '..', 'app', 'src', 'main', 'AndroidManifest.xml');
|
const manifestPath = path.join(__dirname, '..', '..', 'app', 'src', 'main', 'AndroidManifest.xml');
|
||||||
if (buildResults.buildMethod === 'gradle') {
|
const manifest = new AndroidManifest(manifestPath);
|
||||||
manifestPath = path.join(__dirname, '../../AndroidManifest.xml');
|
const pkgName = manifest.getPackageId();
|
||||||
}
|
|
||||||
var manifest = new AndroidManifest(manifestPath);
|
|
||||||
var pkgName = manifest.getPackageId();
|
|
||||||
|
|
||||||
// resolve the target emulator
|
// resolve the target emulator
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (givenTarget && typeof givenTarget === 'object') {
|
if (givenTarget && typeof givenTarget === 'object') {
|
||||||
return givenTarget;
|
return givenTarget;
|
||||||
} else {
|
} else {
|
||||||
@@ -458,8 +447,7 @@ module.exports.install = function (givenTarget, buildResults) {
|
|||||||
}).then(function () {
|
}).then(function () {
|
||||||
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
// 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.
|
// or the app doesn't installed at all, so no error catching needed.
|
||||||
return Q.when().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
|
|
||||||
var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
|
var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
|
||||||
var execOptions = {
|
var execOptions = {
|
||||||
cwd: os.tmpdir(),
|
cwd: os.tmpdir(),
|
||||||
@@ -477,24 +465,21 @@ module.exports.install = function (givenTarget, buildResults) {
|
|||||||
function adbInstallWithOptions (target, apk, opts) {
|
function adbInstallWithOptions (target, apk, opts) {
|
||||||
events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');
|
events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');
|
||||||
|
|
||||||
var command = 'adb -s ' + target + ' install -r "' + apk + '"';
|
const args = ['-s', target, 'install', '-r', apk];
|
||||||
return Q.promise(function (resolve, reject) {
|
return execa('adb', args, opts).then(({ stdout }) => {
|
||||||
child_process.exec(command, opts, function (err, stdout, stderr) {
|
// adb does not return an error code even if installation fails. Instead it puts a specific
|
||||||
if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
|
// message to stdout, so we have to use RegExp matching to detect installation failure.
|
||||||
// adb does not return an error code even if installation fails. Instead it puts a specific
|
if (/Failure/.test(stdout)) {
|
||||||
// message to stdout, so we have to use RegExp matching to detect installation failure.
|
if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
|
||||||
else if (/Failure/.test(stdout)) {
|
stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
|
||||||
if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
|
' or sign and deploy the unsigned apk manually using Android tools.';
|
||||||
stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
|
} else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
|
||||||
' or sign and deploy the unsigned apk manually using Android tools.';
|
stdout += 'You\'re trying to install apk with a lower versionCode that is already installed.' +
|
||||||
} else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
|
'\nEither uninstall an app or increment the versionCode.';
|
||||||
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));
|
throw new CordovaError('Failed to install apk to emulator: ' + stdout);
|
||||||
} else resolve(stdout);
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,7 +506,6 @@ module.exports.install = function (givenTarget, buildResults) {
|
|||||||
});
|
});
|
||||||
// unlock screen
|
// unlock screen
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
|
||||||
events.emit('verbose', 'Unlocking screen...');
|
events.emit('verbose', 'Unlocking screen...');
|
||||||
return Adb.shell(target.target, 'input keyevent 82');
|
return Adb.shell(target.target, 'input keyevent 82');
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
|||||||
@@ -19,23 +19,23 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var device = require('./device'),
|
var device = require('./device');
|
||||||
args = process.argv;
|
var args = process.argv;
|
||||||
|
|
||||||
if(args.length > 2) {
|
if (args.length > 2) {
|
||||||
var install_target;
|
var install_target;
|
||||||
if (args[2].substring(0, 9) == '--target=') {
|
if (args[2].substring(0, 9) === '--target=') {
|
||||||
install_target = args[2].substring(9, args[2].length);
|
install_target = args[2].substring(9, args[2].length);
|
||||||
device.install(install_target).done(null, function(err) {
|
device.install(install_target).catch(function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
device.install().done(null, function(err) {
|
device.install().catch(function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -19,20 +19,20 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var emulator = require('./emulator'),
|
var emulator = require('./emulator');
|
||||||
args = process.argv;
|
var args = process.argv;
|
||||||
|
|
||||||
var install_target;
|
var install_target;
|
||||||
if(args.length > 2) {
|
if (args.length > 2) {
|
||||||
if (args[2].substring(0, 9) == '--target=') {
|
if (args[2].substring(0, 9) === '--target=') {
|
||||||
install_target = args[2].substring(9, args[2].length);
|
install_target = args[2].substring(9, args[2].length);
|
||||||
} else {
|
} else {
|
||||||
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emulator.install(install_target).done(null, function(err) {
|
emulator.install(install_target).catch(function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -22,12 +22,12 @@
|
|||||||
var devices = require('./device');
|
var devices = require('./device');
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
require('./check_reqs').check_android().then(function() {
|
require('./check_reqs').check_android().then(function () {
|
||||||
devices.list().done(function(device_list) {
|
devices.list().then(function (device_list) {
|
||||||
device_list && device_list.forEach(function(dev) {
|
device_list && device_list.forEach(function (dev) {
|
||||||
console.log(dev);
|
console.log(dev);
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -22,12 +22,12 @@
|
|||||||
var emulators = require('./emulator');
|
var emulators = require('./emulator');
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
require('./check_reqs').check_android().then(function() {
|
require('./check_reqs').check_android().then(function () {
|
||||||
emulators.list_images().done(function(emulator_list) {
|
emulators.list_images().then(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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
@@ -20,7 +20,7 @@ SET script_path="%~dp0list-emulator-images"
|
|||||||
IF EXIST %script_path% (
|
IF EXIST %script_path% (
|
||||||
node %script_path% %*
|
node %script_path% %*
|
||||||
) ELSE (
|
) ELSE (
|
||||||
ECHO.
|
ECHO.
|
||||||
ECHO ERROR: Could not find 'list-emulator-images' script in 'cordova\lib' folder, aborting...>&2
|
ECHO ERROR: Could not find 'list-emulator-images' script in 'cordova\lib' folder, aborting...>&2
|
||||||
EXIT /B 1
|
EXIT /B 1
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,12 +22,12 @@
|
|||||||
var emulators = require('./emulator');
|
var emulators = require('./emulator');
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
require('./check_reqs').check_android().then(function() {
|
require('./check_reqs').check_android().then(function () {
|
||||||
emulators.list_started().done(function(emulator_list) {
|
emulators.list_started().then(function (emulator_list) {
|
||||||
emulator_list && emulator_list.forEach(function(emu) {
|
emulator_list && emulator_list.forEach(function (emu) {
|
||||||
console.log(emu);
|
console.log(emu);
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -21,8 +19,7 @@
|
|||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var Q = require('q');
|
var execa = require('execa');
|
||||||
var child_process = require('child_process');
|
|
||||||
var ROOT = path.join(__dirname, '..', '..');
|
var ROOT = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -30,8 +27,7 @@ var ROOT = path.join(__dirname, '..', '..');
|
|||||||
* Returns a promise.
|
* Returns a promise.
|
||||||
*/
|
*/
|
||||||
module.exports.run = function () {
|
module.exports.run = function () {
|
||||||
var d = Q.defer();
|
var adb = execa('adb', ['logcat'], { cwd: os.tmpdir(), stderr: 'inherit' });
|
||||||
var adb = child_process.spawn('adb', ['logcat'], {cwd: os.tmpdir()});
|
|
||||||
|
|
||||||
adb.stdout.on('data', function (data) {
|
adb.stdout.on('data', function (data) {
|
||||||
var lines = data ? data.toString().split('\n') : [];
|
var lines = data ? data.toString().split('\n') : [];
|
||||||
@@ -39,14 +35,7 @@ module.exports.run = function () {
|
|||||||
console.log(out.join('\n'));
|
console.log(out.join('\n'));
|
||||||
});
|
});
|
||||||
|
|
||||||
adb.stderr.on('data', console.error);
|
return adb;
|
||||||
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 () {
|
module.exports.help = function () {
|
||||||
|
|||||||
@@ -20,10 +20,8 @@
|
|||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
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
|
||||||
@@ -38,7 +36,7 @@ buildscript {
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: '*.jar')
|
implementation 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")
|
||||||
}
|
}
|
||||||
@@ -46,7 +44,6 @@ dependencies {
|
|||||||
android {
|
android {
|
||||||
compileSdkVersion cdvCompileSdkVersion
|
compileSdkVersion cdvCompileSdkVersion
|
||||||
buildToolsVersion cdvBuildToolsVersion
|
buildToolsVersion cdvBuildToolsVersion
|
||||||
publishNonDefault true
|
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_6
|
sourceCompatibility JavaVersion.VERSION_1_6
|
||||||
|
|||||||
@@ -14,11 +14,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint unused: vars */
|
var fs = require('fs-extra');
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var shell = require('shelljs');
|
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
@@ -28,22 +25,7 @@ var handlers = {
|
|||||||
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));
|
||||||
|
|
||||||
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
var dest = getInstallDestination(obj);
|
||||||
|
|
||||||
// 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));
|
||||||
@@ -52,48 +34,38 @@ var handlers = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
var dest = getInstallDestination(obj);
|
||||||
|
|
||||||
if (options && options.android_studio === true) {
|
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
|
||||||
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
if (obj.src.endsWith('java')) {
|
||||||
|
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) {
|
||||||
var dest = path.join('libs', path.basename(obj.src));
|
var dest = path.join('app/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) {
|
||||||
var dest = path.join('libs', path.basename(obj.src));
|
var dest = path.join('app/libs', path.basename(obj.src));
|
||||||
if (options && options.android_studio === true) {
|
removeFile(path.resolve(project.projectDir, dest));
|
||||||
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) {
|
||||||
var dest = path.normalize(obj.target);
|
var dest = path.join('app', 'src', 'main', 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) {
|
||||||
var dest = path.normalize(obj.target);
|
var dest = path.join('app', 'src', 'main', obj.target);
|
||||||
if (options && options.android_studio === true) {
|
removeFile(path.resolve(project.projectDir, dest));
|
||||||
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) {
|
||||||
var 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));
|
||||||
@@ -129,7 +101,7 @@ var handlers = {
|
|||||||
|
|
||||||
if (obj.custom) {
|
if (obj.custom) {
|
||||||
var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
|
||||||
removeFile(project.projectDir, subRelativeDir);
|
removeFile(path.resolve(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.
|
||||||
var parDir = path.dirname(subDir);
|
var parDir = path.dirname(subDir);
|
||||||
@@ -170,12 +142,12 @@ var handlers = {
|
|||||||
|
|
||||||
if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
||||||
|
|
||||||
removeFileF(path.resolve(project.www, target));
|
removeFile(path.resolve(project.www, target));
|
||||||
removeFileF(path.resolve(project.www, 'plugins', plugin.id));
|
removeFile(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
|
||||||
removeFileF(path.resolve(project.platformWww, target));
|
removeFile(path.resolve(project.platformWww, target));
|
||||||
removeFileF(path.resolve(project.platformWww, 'plugins', plugin.id));
|
removeFile(path.resolve(project.platformWww, 'plugins', plugin.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -193,13 +165,13 @@ var handlers = {
|
|||||||
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
|
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
|
||||||
|
|
||||||
var wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
|
var wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
|
||||||
shell.mkdir('-p', path.dirname(wwwDest));
|
fs.ensureDirSync(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
|
||||||
var platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
|
var platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
|
||||||
shell.mkdir('-p', path.dirname(platformWwwDest));
|
fs.ensureDirSync(path.dirname(platformWwwDest));
|
||||||
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
|
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -244,14 +216,11 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
|
|||||||
// check that dest path is located in project directory
|
// check that dest path is located in project directory
|
||||||
if (dest.indexOf(project_dir) !== 0) { 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'); }
|
||||||
|
|
||||||
shell.mkdir('-p', path.dirname(dest));
|
fs.ensureDirSync(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 {
|
||||||
shell.cp('-f', src, dest);
|
fs.copySync(src, dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,11 +234,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)) {
|
||||||
shell.rm('-Rf', dest);
|
fs.removeSync(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.statSync(src).isDirectory()) {
|
if (fs.statSync(src).isDirectory()) {
|
||||||
shell.mkdir('-p', dest);
|
fs.ensureDirSync(path.dirname(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));
|
||||||
});
|
});
|
||||||
@@ -278,15 +247,8 @@ function symlinkFileOrDirTree (src, dest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if file exists and then deletes. Error if doesn't exist
|
function removeFile (file) {
|
||||||
function removeFile (project_dir, src) {
|
fs.removeSync(file);
|
||||||
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
|
||||||
@@ -299,7 +261,7 @@ function removeFileAndParents (baseDir, destFile, stopper) {
|
|||||||
var file = path.resolve(baseDir, destFile);
|
var file = path.resolve(baseDir, destFile);
|
||||||
if (!fs.existsSync(file)) return;
|
if (!fs.existsSync(file)) return;
|
||||||
|
|
||||||
removeFileF(file);
|
removeFile(file);
|
||||||
|
|
||||||
// check if directory is empty
|
// check if directory is empty
|
||||||
var curDir = path.dirname(file);
|
var curDir = path.dirname(file);
|
||||||
@@ -318,3 +280,44 @@ 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) {
|
||||||
|
var APP_MAIN_PREFIX = 'app/src/main';
|
||||||
|
var PATH_SEPARATOR = '/';
|
||||||
|
|
||||||
|
var PATH_SEP_MATCH = '\\' + PATH_SEPARATOR;
|
||||||
|
var PATH_SEP_OR_EOL_MATCH = '(\\' + PATH_SEPARATOR + '|$)';
|
||||||
|
|
||||||
|
var appReg = new RegExp('^app' + PATH_SEP_OR_EOL_MATCH);
|
||||||
|
var libsReg = new RegExp('^libs' + PATH_SEP_OR_EOL_MATCH);
|
||||||
|
var srcReg = new RegExp('^src' + PATH_SEP_OR_EOL_MATCH);
|
||||||
|
var 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,12 +16,10 @@
|
|||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint no-useless-escape: 0 */
|
|
||||||
|
|
||||||
var Q = require('q');
|
var fs = require('fs-extra');
|
||||||
var fs = require('fs');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var shell = require('shelljs');
|
const nopt = require('nopt');
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
var AndroidManifest = require('./AndroidManifest');
|
var AndroidManifest = require('./AndroidManifest');
|
||||||
var checkReqs = require('./check_reqs');
|
var checkReqs = require('./check_reqs');
|
||||||
@@ -32,17 +30,58 @@ var FileUpdater = require('cordova-common').FileUpdater;
|
|||||||
var PlatformJson = require('cordova-common').PlatformJson;
|
var PlatformJson = require('cordova-common').PlatformJson;
|
||||||
var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger;
|
var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger;
|
||||||
var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
|
var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
|
||||||
|
const utils = require('./utils');
|
||||||
|
|
||||||
|
const GradlePropertiesParser = require('./config/GradlePropertiesParser');
|
||||||
|
|
||||||
|
function parseArguments (argv) {
|
||||||
|
return nopt({
|
||||||
|
// `jvmargs` is a valid option however, we don't actually want to parse it because we want the entire string as is.
|
||||||
|
// jvmargs: String
|
||||||
|
}, {}, argv || [], 0);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.prepare = function (cordovaProject, options) {
|
module.exports.prepare = function (cordovaProject, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
let args = {};
|
||||||
|
if (options && options.options) {
|
||||||
|
args = parseArguments(options.options.argv);
|
||||||
|
}
|
||||||
|
|
||||||
var platformJson = PlatformJson.load(this.locations.root, this.platform);
|
var platformJson = PlatformJson.load(this.locations.root, this.platform);
|
||||||
var munger = new PlatformMunger(this.platform, this.locations.root, platformJson, new PluginInfoProvider());
|
var munger = new PlatformMunger(this.platform, this.locations.root, platformJson, new PluginInfoProvider());
|
||||||
|
|
||||||
this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations);
|
this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations);
|
||||||
|
|
||||||
|
// Get the min SDK version from config.xml
|
||||||
|
const minSdkVersion = this._config.getPreference('android-minSdkVersion', 'android');
|
||||||
|
const maxSdkVersion = this._config.getPreference('android-maxSdkVersion', 'android');
|
||||||
|
const targetSdkVersion = this._config.getPreference('android-targetSdkVersion', 'android');
|
||||||
|
const androidXEnabled = this._config.getPreference('AndroidXEnabled', 'android');
|
||||||
|
const isGradlePluginKotlinEnabled = this._config.getPreference('GradlePluginKotlinEnabled', 'android');
|
||||||
|
const gradlePluginKotlinCodeStyle = this._config.getPreference('GradlePluginKotlinCodeStyle', 'android');
|
||||||
|
|
||||||
|
const gradlePropertiesUserConfig = {};
|
||||||
|
if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion;
|
||||||
|
if (maxSdkVersion) gradlePropertiesUserConfig.cdvMaxSdkVersion = maxSdkVersion;
|
||||||
|
if (targetSdkVersion) gradlePropertiesUserConfig.cdvTargetSdkVersion = targetSdkVersion;
|
||||||
|
if (args.jvmargs) gradlePropertiesUserConfig['org.gradle.jvmargs'] = args.jvmargs;
|
||||||
|
if (isGradlePluginKotlinEnabled) {
|
||||||
|
gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both 'useAndroidX' and 'enableJetifier' are linked together.
|
||||||
|
if (androidXEnabled) {
|
||||||
|
gradlePropertiesUserConfig['android.useAndroidX'] = androidXEnabled;
|
||||||
|
gradlePropertiesUserConfig['android.enableJetifier'] = androidXEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gradlePropertiesParser = new GradlePropertiesParser(this.locations.root);
|
||||||
|
gradlePropertiesParser.configure(gradlePropertiesUserConfig);
|
||||||
|
|
||||||
// Update own www dir with project's www assets and plugins' assets and js-files
|
// Update own www dir with project's www assets and plugins' assets and js-files
|
||||||
return Q.when(updateWww(cordovaProject, this.locations)).then(function () {
|
return Promise.resolve(updateWww(cordovaProject, this.locations)).then(function () {
|
||||||
// update project according to config.xml changes.
|
// update project according to config.xml changes.
|
||||||
return updateProjectAccordingTo(self._config, self.locations);
|
return updateProjectAccordingTo(self._config, self.locations);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
@@ -62,13 +101,13 @@ module.exports.clean = function (options) {
|
|||||||
var projectRoot = path.resolve(this.root, '../..');
|
var projectRoot = path.resolve(this.root, '../..');
|
||||||
if ((options && options.noPrepare) || !fs.existsSync(this.locations.configXml) ||
|
if ((options && options.noPrepare) || !fs.existsSync(this.locations.configXml) ||
|
||||||
!fs.existsSync(this.locations.configXml)) {
|
!fs.existsSync(this.locations.configXml)) {
|
||||||
return Q();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
var projectConfig = new ConfigParser(this.locations.configXml);
|
var projectConfig = new ConfigParser(this.locations.configXml);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
cleanWww(projectRoot, self.locations);
|
cleanWww(projectRoot, self.locations);
|
||||||
cleanIcons(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
cleanIcons(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
||||||
cleanSplashes(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
cleanSplashes(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
|
||||||
@@ -95,7 +134,7 @@ function updateConfigFilesFrom (sourceConfig, configMunger, locations) {
|
|||||||
|
|
||||||
// First cleanup current config and merge project's one into own
|
// First cleanup current config and merge project's one into own
|
||||||
// Overwrite platform config.xml with defaults.xml.
|
// Overwrite platform config.xml with defaults.xml.
|
||||||
shell.cp('-f', locations.defaultConfigXml, locations.configXml);
|
fs.copySync(locations.defaultConfigXml, locations.configXml);
|
||||||
|
|
||||||
// Then apply config changes from global munge to all config files
|
// Then apply config changes from global munge to all config files
|
||||||
// in project (including project's config)
|
// in project (including project's config)
|
||||||
@@ -171,14 +210,14 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
|||||||
var strings = xmlHelpers.parseElementtreeSync(locations.strings);
|
var strings = xmlHelpers.parseElementtreeSync(locations.strings);
|
||||||
|
|
||||||
var name = platformConfig.name();
|
var name = platformConfig.name();
|
||||||
strings.find('string[@name="app_name"]').text = name.replace(/\'/g, '\\\'');
|
strings.find('string[@name="app_name"]').text = name.replace(/'/g, '\\\'');
|
||||||
|
|
||||||
var shortName = platformConfig.shortName && platformConfig.shortName();
|
var shortName = platformConfig.shortName && platformConfig.shortName();
|
||||||
if (shortName && shortName !== name) {
|
if (shortName && shortName !== name) {
|
||||||
strings.find('string[@name="launcher_name"]').text = shortName.replace(/\'/g, '\\\'');
|
strings.find('string[@name="launcher_name"]').text = shortName.replace(/'/g, '\\\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(locations.strings, strings.write({indent: 4}), 'utf-8');
|
fs.writeFileSync(locations.strings, strings.write({ indent: 4 }), 'utf-8');
|
||||||
events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
|
events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
|
||||||
|
|
||||||
// Java packages cannot support dashes
|
// Java packages cannot support dashes
|
||||||
@@ -194,15 +233,13 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
|||||||
manifest.setVersionName(platformConfig.version())
|
manifest.setVersionName(platformConfig.version())
|
||||||
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
|
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
|
||||||
.setPackageId(androidPkgName)
|
.setPackageId(androidPkgName)
|
||||||
.setMinSdkVersion(platformConfig.getPreference('android-minSdkVersion', 'android'))
|
|
||||||
.setMaxSdkVersion(platformConfig.getPreference('android-maxSdkVersion', 'android'))
|
|
||||||
.setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
|
|
||||||
.write();
|
.write();
|
||||||
|
|
||||||
// Java file paths shouldn't be hard coded
|
// Java file paths shouldn't be hard coded
|
||||||
var javaPattern = path.join(locations.javaSrc, manifestId.replace(/\./g, '/'), '*.java');
|
const javaDirectory = path.join(locations.javaSrc, manifestId.replace(/\./g, '/'));
|
||||||
var java_files = shell.ls(javaPattern).filter(function (f) {
|
const javaPattern = /\.java$/;
|
||||||
return shell.grep(/extends\s+CordovaActivity/g, f);
|
const java_files = utils.scanDirectory(javaDirectory, javaPattern, true).filter(function (f) {
|
||||||
|
return utils.grep(f, /extends\s+CordovaActivity/g) !== null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (java_files.length === 0) {
|
if (java_files.length === 0) {
|
||||||
@@ -211,18 +248,24 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
|||||||
events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found. Guessing at the first one, ' + java_files[0]);
|
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]));
|
const destFile = java_files[0];
|
||||||
shell.mkdir('-p', path.dirname(destFile));
|
|
||||||
shell.sed(/package [\w\.]*;/, 'package ' + androidPkgName + ';', java_files[0]).to(destFile);
|
// var destFile = path.join(locations.root, 'app', 'src', 'main', 'java', androidPkgName.replace(/\./g, '/'), path.basename(java_files[0]));
|
||||||
|
// fs.ensureDirSync(path.dirname(destFile));
|
||||||
|
// events.emit('verbose', java_files[0]);
|
||||||
|
// events.emit('verbose', destFile);
|
||||||
|
// console.log(locations);
|
||||||
|
// fs.copySync(java_files[0], destFile);
|
||||||
|
utils.replaceFileContents(destFile, /package [\w.]*;/, 'package ' + androidPkgName + ';');
|
||||||
events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + destFile);
|
events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + destFile);
|
||||||
|
|
||||||
var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() ?
|
var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin()
|
||||||
manifestId.toUpperCase() !== androidPkgName.toUpperCase() :
|
? manifestId.toUpperCase() !== androidPkgName.toUpperCase()
|
||||||
manifestId !== androidPkgName;
|
: manifestId !== androidPkgName;
|
||||||
|
|
||||||
if (removeOrigPkg) {
|
if (removeOrigPkg) {
|
||||||
// If package was name changed we need to remove old java with main activity
|
// If package was name changed we need to remove old java with main activity
|
||||||
shell.rm('-Rf', java_files[0]);
|
fs.removeSync(java_files[0]);
|
||||||
// remove any empty directories
|
// remove any empty directories
|
||||||
var currentDir = path.dirname(java_files[0]);
|
var currentDir = path.dirname(java_files[0]);
|
||||||
var sourcesRoot = path.resolve(locations.root, 'src');
|
var sourcesRoot = path.resolve(locations.root, 'src');
|
||||||
@@ -265,6 +308,14 @@ function getImageResourcePath (resourcesDir, type, density, name, sourceName) {
|
|||||||
return resourcePath;
|
return resourcePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAdaptiveImageResourcePath (resourcesDir, type, density, name, sourceName) {
|
||||||
|
if (/\.9\.png$/.test(sourceName)) {
|
||||||
|
name = name.replace(/\.png$/, '.9.png');
|
||||||
|
}
|
||||||
|
var resourcePath = path.join(resourcesDir, (density ? type + '-' + density + '-v26' : type), name);
|
||||||
|
return resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
function updateSplashes (cordovaProject, platformResourcesDir) {
|
function updateSplashes (cordovaProject, platformResourcesDir) {
|
||||||
var resources = cordovaProject.projectConfig.getSplashScreens('android');
|
var resources = cordovaProject.projectConfig.getSplashScreens('android');
|
||||||
|
|
||||||
@@ -314,20 +365,202 @@ function cleanSplashes (projectRoot, projectConfig, platformResourcesDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateIcons (cordovaProject, platformResourcesDir) {
|
function updateIcons (cordovaProject, platformResourcesDir) {
|
||||||
var icons = cordovaProject.projectConfig.getIcons('android');
|
const icons = cordovaProject.projectConfig.getIcons('android');
|
||||||
|
|
||||||
// if there are icon elements in config.xml
|
// Skip if there are no app defined icons in config.xml
|
||||||
if (icons.length === 0) {
|
if (icons.length === 0) {
|
||||||
events.emit('verbose', 'This app does not have launcher icons defined');
|
events.emit('verbose', 'This app does not have launcher icons defined');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resourceMap = mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'icon.png');
|
// 1. loop icons determin if there is an error in the setup.
|
||||||
|
// 2. during initial loop, also setup for legacy support.
|
||||||
|
const errorMissingAttributes = [];
|
||||||
|
const errorLegacyIconNeeded = [];
|
||||||
|
let hasAdaptive = false;
|
||||||
|
icons.forEach((icon, key) => {
|
||||||
|
if (
|
||||||
|
(icon.background && !icon.foreground) ||
|
||||||
|
(!icon.background && icon.foreground) ||
|
||||||
|
(!icon.background && !icon.foreground && !icon.src)
|
||||||
|
) {
|
||||||
|
errorMissingAttributes.push(icon.density ? icon.density : 'size=' + (icon.height || icon.width));
|
||||||
|
}
|
||||||
|
|
||||||
var android_icons = {};
|
if (icon.foreground) {
|
||||||
var default_icon;
|
hasAdaptive = true;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!icon.src &&
|
||||||
|
(
|
||||||
|
icon.foreground.startsWith('@color') ||
|
||||||
|
path.extname(path.basename(icon.foreground)) === '.xml'
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
errorLegacyIconNeeded.push(icon.density ? icon.density : 'size=' + (icon.height || icon.width));
|
||||||
|
} else if (!icon.src) {
|
||||||
|
icons[key].src = icon.foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const errorMessage = [];
|
||||||
|
if (errorMissingAttributes.length > 0) {
|
||||||
|
errorMessage.push('One of the following attributes are set but missing the other for the density type: ' + errorMissingAttributes.join(', ') + '. Please ensure that all require attributes are defined.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorLegacyIconNeeded.length > 0) {
|
||||||
|
errorMessage.push('For the following icons with the density of: ' + errorLegacyIconNeeded.join(', ') + ', adaptive foreground with a defined color or vector can not be used as a standard fallback icon for older Android devices. To support older Android environments, please provide a value for the src attribute.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMessage.length > 0) {
|
||||||
|
throw new CordovaError(errorMessage.join(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
let resourceMap = Object.assign(
|
||||||
|
{},
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher.png'),
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher_foreground.png'),
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher_background.png'),
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher_foreground.xml'),
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher_background.xml'),
|
||||||
|
mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher.xml')
|
||||||
|
);
|
||||||
|
|
||||||
|
const preparedIcons = prepareIcons(icons);
|
||||||
|
|
||||||
|
if (hasAdaptive) {
|
||||||
|
resourceMap = updateIconResourceForAdaptive(preparedIcons, resourceMap, platformResourcesDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceMap = updateIconResourceForLegacy(preparedIcons, resourceMap, platformResourcesDir);
|
||||||
|
|
||||||
|
events.emit('verbose', 'Updating icons at ' + platformResourcesDir);
|
||||||
|
FileUpdater.updatePaths(resourceMap, { rootDir: cordovaProject.root }, logFileOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateIconResourceForAdaptive (preparedIcons, resourceMap, platformResourcesDir) {
|
||||||
|
const android_icons = preparedIcons.android_icons;
|
||||||
|
const default_icon = preparedIcons.default_icon;
|
||||||
|
|
||||||
|
// The source paths for icons and splashes are relative to
|
||||||
|
// project's config.xml location, so we use it as base path.
|
||||||
|
let background;
|
||||||
|
let foreground;
|
||||||
|
let targetPathBackground;
|
||||||
|
let targetPathForeground;
|
||||||
|
|
||||||
|
for (const density in android_icons) {
|
||||||
|
let backgroundVal = '@mipmap/ic_launcher_background';
|
||||||
|
let foregroundVal = '@mipmap/ic_launcher_foreground';
|
||||||
|
|
||||||
|
background = android_icons[density].background;
|
||||||
|
foreground = android_icons[density].foreground;
|
||||||
|
|
||||||
|
if (!background || !foreground) {
|
||||||
|
// This icon isn't an adaptive icon, so skip it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (background.startsWith('@color')) {
|
||||||
|
// Colors Use Case
|
||||||
|
backgroundVal = background; // Example: @color/background_foobar_1
|
||||||
|
} else if (path.extname(path.basename(background)) === '.xml') {
|
||||||
|
// Vector Use Case
|
||||||
|
targetPathBackground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', density, 'ic_launcher_background.xml', path.basename(android_icons[density].background));
|
||||||
|
resourceMap[targetPathBackground] = android_icons[density].background;
|
||||||
|
} else if (path.extname(path.basename(background)) === '.png') {
|
||||||
|
// Images Use Case
|
||||||
|
targetPathBackground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', density, 'ic_launcher_background.png', path.basename(android_icons[density].background));
|
||||||
|
resourceMap[targetPathBackground] = android_icons[density].background;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foreground.startsWith('@color')) {
|
||||||
|
// Colors Use Case
|
||||||
|
foregroundVal = foreground;
|
||||||
|
} else if (path.extname(path.basename(foreground)) === '.xml') {
|
||||||
|
// Vector Use Case
|
||||||
|
targetPathForeground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', density, 'ic_launcher_foreground.xml', path.basename(android_icons[density].foreground));
|
||||||
|
resourceMap[targetPathForeground] = android_icons[density].foreground;
|
||||||
|
} else if (path.extname(path.basename(foreground)) === '.png') {
|
||||||
|
// Images Use Case
|
||||||
|
targetPathForeground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', density, 'ic_launcher_foreground.png', path.basename(android_icons[density].foreground));
|
||||||
|
resourceMap[targetPathForeground] = android_icons[density].foreground;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create an XML for DPI and set color
|
||||||
|
const icLauncherTemplate = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="` + backgroundVal + `" />
|
||||||
|
<foreground android:drawable="` + foregroundVal + `" />
|
||||||
|
</adaptive-icon>`;
|
||||||
|
|
||||||
|
const launcherXmlPath = path.join(platformResourcesDir, 'mipmap-' + density + '-v26', 'ic_launcher.xml');
|
||||||
|
|
||||||
|
// Remove the XML from the resourceMap so the file does not get removed.
|
||||||
|
delete resourceMap[launcherXmlPath];
|
||||||
|
|
||||||
|
fs.writeFileSync(path.resolve(launcherXmlPath), icLauncherTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// There's no "default" drawable, so assume default == mdpi.
|
||||||
|
if (default_icon && !android_icons.mdpi) {
|
||||||
|
let defaultTargetPathBackground;
|
||||||
|
let defaultTargetPathForeground;
|
||||||
|
|
||||||
|
if (background.startsWith('@color')) {
|
||||||
|
// Colors Use Case
|
||||||
|
targetPathBackground = default_icon.background;
|
||||||
|
} else if (path.extname(path.basename(background)) === '.xml') {
|
||||||
|
// Vector Use Case
|
||||||
|
defaultTargetPathBackground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', 'mdpi', 'ic_launcher_background.xml', path.basename(default_icon.background));
|
||||||
|
resourceMap[defaultTargetPathBackground] = default_icon.background;
|
||||||
|
} else if (path.extname(path.basename(background)) === '.png') {
|
||||||
|
// Images Use Case
|
||||||
|
defaultTargetPathBackground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', 'mdpi', 'ic_launcher_background.png', path.basename(default_icon.background));
|
||||||
|
resourceMap[defaultTargetPathBackground] = default_icon.background;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foreground.startsWith('@color')) {
|
||||||
|
// Colors Use Case
|
||||||
|
targetPathForeground = default_icon.foreground;
|
||||||
|
} else if (path.extname(path.basename(foreground)) === '.xml') {
|
||||||
|
// Vector Use Case
|
||||||
|
defaultTargetPathForeground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', 'mdpi', 'ic_launcher_foreground.xml', path.basename(default_icon.foreground));
|
||||||
|
resourceMap[defaultTargetPathForeground] = default_icon.foreground;
|
||||||
|
} else if (path.extname(path.basename(foreground)) === '.png') {
|
||||||
|
// Images Use Case
|
||||||
|
defaultTargetPathForeground = getAdaptiveImageResourcePath(platformResourcesDir, 'mipmap', 'mdpi', 'ic_launcher_foreground.png', path.basename(default_icon.foreground));
|
||||||
|
resourceMap[defaultTargetPathForeground] = default_icon.foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateIconResourceForLegacy (preparedIcons, resourceMap, platformResourcesDir) {
|
||||||
|
const android_icons = preparedIcons.android_icons;
|
||||||
|
const default_icon = preparedIcons.default_icon;
|
||||||
|
|
||||||
|
// 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, 'ic_launcher.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', 'ic_launcher.png', path.basename(default_icon.src));
|
||||||
|
resourceMap[defaultTargetPath] = default_icon.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareIcons (icons) {
|
||||||
// http://developer.android.com/design/style/iconography.html
|
// http://developer.android.com/design/style/iconography.html
|
||||||
var sizeToDensityMap = {
|
const SIZE_TO_DENSITY_MAP = {
|
||||||
36: 'ldpi',
|
36: 'ldpi',
|
||||||
48: 'mdpi',
|
48: 'mdpi',
|
||||||
72: 'hdpi',
|
72: 'hdpi',
|
||||||
@@ -335,11 +568,15 @@ function updateIcons (cordovaProject, platformResourcesDir) {
|
|||||||
144: 'xxhdpi',
|
144: 'xxhdpi',
|
||||||
192: 'xxxhdpi'
|
192: 'xxxhdpi'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const android_icons = {};
|
||||||
|
let default_icon;
|
||||||
|
|
||||||
// find the best matching icon for a given density or size
|
// find the best matching icon for a given density or size
|
||||||
// @output android_icons
|
// @output android_icons
|
||||||
var parseIcon = function (icon, icon_size) {
|
var parseIcon = function (icon, icon_size) {
|
||||||
// do I have a platform icon for that density already
|
// do I have a platform icon for that density already
|
||||||
var density = icon.density || sizeToDensityMap[icon_size];
|
var density = icon.density || SIZE_TO_DENSITY_MAP[icon_size];
|
||||||
if (!density) {
|
if (!density) {
|
||||||
// invalid icon defition ( or unsupported size)
|
// invalid icon defition ( or unsupported size)
|
||||||
return;
|
return;
|
||||||
@@ -355,12 +592,34 @@ function updateIcons (cordovaProject, platformResourcesDir) {
|
|||||||
for (var i = 0; i < icons.length; i++) {
|
for (var i = 0; i < icons.length; i++) {
|
||||||
var icon = icons[i];
|
var icon = icons[i];
|
||||||
var size = icon.width;
|
var size = icon.width;
|
||||||
|
|
||||||
if (!size) {
|
if (!size) {
|
||||||
size = icon.height;
|
size = icon.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!size && !icon.density) {
|
if (!size && !icon.density) {
|
||||||
if (default_icon) {
|
if (default_icon) {
|
||||||
events.emit('verbose', 'Found extra default icon: ' + icon.src + ' (ignoring in favor of ' + default_icon.src + ')');
|
const found = {};
|
||||||
|
const favor = {};
|
||||||
|
|
||||||
|
// populating found icon.
|
||||||
|
if (icon.background && icon.foreground) {
|
||||||
|
found.background = icon.background;
|
||||||
|
found.foreground = icon.foreground;
|
||||||
|
}
|
||||||
|
if (icon.src) {
|
||||||
|
found.src = icon.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (default_icon.background && default_icon.foreground) {
|
||||||
|
favor.background = default_icon.background;
|
||||||
|
favor.foreground = default_icon.foreground;
|
||||||
|
}
|
||||||
|
if (default_icon.src) {
|
||||||
|
favor.src = default_icon.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
events.emit('verbose', 'Found extra default icon: ' + JSON.stringify(found) + ' and ignoring in favor of ' + JSON.stringify(favor) + '.');
|
||||||
} else {
|
} else {
|
||||||
default_icon = icon;
|
default_icon = icon;
|
||||||
}
|
}
|
||||||
@@ -369,45 +628,45 @@ function updateIcons (cordovaProject, platformResourcesDir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The source paths for icons and splashes are relative to
|
return {
|
||||||
// project's config.xml location, so we use it as base path.
|
android_icons: android_icons,
|
||||||
for (var density in android_icons) {
|
default_icon: default_icon
|
||||||
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) {
|
function cleanIcons (projectRoot, projectConfig, platformResourcesDir) {
|
||||||
var icons = projectConfig.getIcons('android');
|
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.
|
// Skip if there are no app defined icons in config.xml
|
||||||
FileUpdater.updatePaths(
|
if (icons.length === 0) {
|
||||||
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
|
events.emit('verbose', 'This app does not have launcher icons defined');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resourceMap = Object.assign(
|
||||||
|
{},
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher.png'),
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher_foreground.png'),
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher_background.png'),
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher_foreground.xml'),
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher_background.xml'),
|
||||||
|
mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher.xml')
|
||||||
|
);
|
||||||
|
|
||||||
|
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.
|
* Gets a map containing resources of a specified name from all drawable folders in a directory.
|
||||||
*/
|
*/
|
||||||
function mapImageResources (rootDir, subDir, type, resourceName) {
|
function mapImageResources (rootDir, subDir, type, resourceName) {
|
||||||
var pathMap = {};
|
const pathMap = {};
|
||||||
shell.ls(path.join(rootDir, subDir, type + '-*')).forEach(function (drawableFolder) {
|
const pattern = new RegExp(type + '+-.+');
|
||||||
var imagePath = path.join(subDir, path.basename(drawableFolder), resourceName);
|
utils.scanDirectory(path.join(rootDir, subDir), pattern).forEach(function (drawableFolder) {
|
||||||
|
const imagePath = path.join(subDir, path.basename(drawableFolder), resourceName);
|
||||||
pathMap[imagePath] = null;
|
pathMap[imagePath] = null;
|
||||||
});
|
});
|
||||||
return pathMap;
|
return pathMap;
|
||||||
@@ -445,8 +704,7 @@ function cleanFileResources (projectRoot, projectConfig, platformDir) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
FileUpdater.updatePaths(
|
FileUpdater.updatePaths(
|
||||||
resourceMap, {
|
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
|
||||||
rootDir: projectRoot, all: true}, logFileOp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,8 +17,6 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var events = require('cordova-common').events;
|
var events = require('cordova-common').events;
|
||||||
@@ -29,21 +25,19 @@ 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} attemts_left - The number of times to retry the passed call.
|
* @arg {Number} attemptsLeft - 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 = function (attemts_left, promiseFunction) {
|
module.exports.retryPromise = function (attemptsLeft, promiseFunction) {
|
||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
// get all trailing arguments, by skipping the first two (attemts_left and
|
// get all trailing arguments, by skipping the first two (attemptsLeft and
|
||||||
// promiseFunction) because they shouldn't get passed to promiseFunction
|
// promiseFunction) because they shouldn't get passed to promiseFunction
|
||||||
var promiseFunctionArguments = Array.prototype.slice.call(arguments, 2);
|
var promiseFunctionArguments = Array.prototype.slice.call(arguments, 2);
|
||||||
|
|
||||||
return promiseFunction.apply(undefined, promiseFunctionArguments).then(
|
return promiseFunction.apply(undefined, promiseFunctionArguments).then(
|
||||||
|
|
||||||
// on success pass results through
|
// on success pass results through
|
||||||
function onFulfilled (value) {
|
function onFulfilled (value) {
|
||||||
return value;
|
return value;
|
||||||
@@ -51,17 +45,16 @@ module.exports.retryPromise = function (attemts_left, promiseFunction) {
|
|||||||
|
|
||||||
// on rejection either retry, or throw the error
|
// on rejection either retry, or throw the error
|
||||||
function onRejected (error) {
|
function onRejected (error) {
|
||||||
|
attemptsLeft -= 1;
|
||||||
|
|
||||||
attemts_left -= 1;
|
if (attemptsLeft < 1) {
|
||||||
|
|
||||||
if (attemts_left < 1) {
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
events.emit('verbose', 'A retried call failed. Retrying ' + attemts_left + ' more time(s).');
|
events.emit('verbose', 'A retried call failed. Retrying ' + attemptsLeft + ' more time(s).');
|
||||||
|
|
||||||
// retry call self again with the same arguments, except attemts_left is now lower
|
// retry call self again with the same arguments, except attemptsLeft is now lower
|
||||||
var fullArguments = [attemts_left, promiseFunction].concat(promiseFunctionArguments);
|
var fullArguments = [attemptsLeft, promiseFunction].concat(promiseFunctionArguments);
|
||||||
return module.exports.retryPromise.apply(undefined, fullArguments);
|
return module.exports.retryPromise.apply(undefined, fullArguments);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/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
|
||||||
@@ -19,14 +17,11 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint loopfunc:true */
|
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var build = require('./build');
|
|
||||||
var emulator = require('./emulator');
|
var emulator = require('./emulator');
|
||||||
var device = require('./device');
|
var device = require('./device');
|
||||||
var Q = require('q');
|
var PackageType = require('./PackageType');
|
||||||
var events = require('cordova-common').events;
|
const { CordovaError, events } = require('cordova-common');
|
||||||
|
|
||||||
function getInstallTarget (runOptions) {
|
function getInstallTarget (runOptions) {
|
||||||
var install_target;
|
var install_target;
|
||||||
@@ -52,11 +47,12 @@ function getInstallTarget (runOptions) {
|
|||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
module.exports.run = function (runOptions) {
|
module.exports.run = function (runOptions) {
|
||||||
|
runOptions = runOptions || {};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var install_target = getInstallTarget(runOptions);
|
var install_target = getInstallTarget(runOptions);
|
||||||
|
|
||||||
return Q().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
if (!install_target) {
|
if (!install_target) {
|
||||||
// no target given, deploy to device if available, otherwise use the emulator.
|
// no target given, deploy to device if available, otherwise use the emulator.
|
||||||
return device.list().then(function (device_list) {
|
return device.list().then(function (device_list) {
|
||||||
@@ -98,21 +94,30 @@ module.exports.run = function (runOptions) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Q.reject('Target \'' + install_target + '\' not found, unable to run project');
|
return Promise.reject(new CordovaError(`Target '${install_target}' not found, unable to run project`));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).then(function (resolvedTarget) {
|
}).then(function (resolvedTarget) {
|
||||||
// Better just call self.build, but we're doing some processing of
|
return new Promise((resolve) => {
|
||||||
// build results (according to platformApi spec) so they are in different
|
const builder = require('./builders/builders').getBuilder();
|
||||||
// format than emulator.install expects.
|
const buildOptions = require('./build').parseBuildOptions(runOptions, null, self.root);
|
||||||
// TODO: Update emulator/device.install to handle this change
|
|
||||||
return build.run.call(self, runOptions, resolvedTarget).then(function (buildResults) {
|
// Android app bundles cannot be deployed directly to the device
|
||||||
if (resolvedTarget.isEmulator) {
|
if (buildOptions.packageType === PackageType.BUNDLE) {
|
||||||
|
const packageTypeErrorMessage = 'Package type "bundle" is not supported during cordova run.';
|
||||||
|
events.emit('error', packageTypeErrorMessage);
|
||||||
|
throw packageTypeErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(builder.fetchBuildResults(buildOptions.buildType, buildOptions.arch));
|
||||||
|
}).then(function (buildResults) {
|
||||||
|
if (resolvedTarget && resolvedTarget.isEmulator) {
|
||||||
return emulator.wait_for_boot(resolvedTarget.target).then(function () {
|
return emulator.wait_for_boot(resolvedTarget.target).then(function () {
|
||||||
return emulator.install(resolvedTarget, buildResults);
|
return emulator.install(resolvedTarget, buildResults);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return device.install(resolvedTarget, buildResults);
|
return device.install(resolvedTarget, buildResults);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,21 +19,20 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var emulator = require('./emulator'),
|
var emulator = require('./emulator');
|
||||||
args = process.argv;
|
var args = process.argv;
|
||||||
|
|
||||||
var install_target;
|
var install_target;
|
||||||
if(args.length > 2) {
|
if (args.length > 2) {
|
||||||
if (args[2].substring(0, 9) == '--target=') {
|
if (args[2].substring(0, 9) === '--target=') {
|
||||||
install_target = args[2].substring(9, args[2].length);
|
install_target = args[2].substring(9, args[2].length);
|
||||||
} else {
|
} else {
|
||||||
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emulator.start(install_target).done(null, function(err) {
|
emulator.start(install_target).catch(function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
:: to you under the Apache License, Version 2.0 (the
|
:: to you under the Apache License, Version 2.0 (the
|
||||||
:: "License"); you may not use this file except in compliance
|
:: "License"); you may not use this file except in compliance
|
||||||
:: with the License. You may obtain a copy of the License at
|
:: with the License. You may obtain a copy of the License at
|
||||||
::
|
::
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
::
|
::
|
||||||
:: Unless required by applicable law or agreed to in writing,
|
:: Unless required by applicable law or agreed to in writing,
|
||||||
:: software distributed under the License is distributed on an
|
:: software distributed under the License is distributed on an
|
||||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Provides a set of utility methods, which can also be spied on during unit tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO: Perhaps this should live in cordova-common?
|
||||||
|
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads, searches, and replaces the found occurences with replacementString and then writes the file back out.
|
||||||
|
* A backup is not made.
|
||||||
|
*
|
||||||
|
* @param {string} file A file path to a readable & writable file
|
||||||
|
* @param {RegExp} searchRegex The search regex
|
||||||
|
* @param {string} replacementString The string to replace the found occurences
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
exports.replaceFileContents = function (file, searchRegex, replacementString) {
|
||||||
|
let contents = fs.readFileSync(file).toString();
|
||||||
|
contents = contents.replace(searchRegex, replacementString);
|
||||||
|
fs.writeFileSync(file, contents);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a file and scans for regex. Returns the line of the first occurence or null if no occurences are found.
|
||||||
|
*
|
||||||
|
* @param {string} file A file path
|
||||||
|
* @param {RegExp} regex A search regex
|
||||||
|
* @returns string|null
|
||||||
|
*/
|
||||||
|
exports.grep = function (file, regex) {
|
||||||
|
const contents = fs.readFileSync(file).toString().replace(/\\r/g, '').split('\n');
|
||||||
|
for (let i = 0; i < contents.length; i++) {
|
||||||
|
const line = contents[i];
|
||||||
|
if (regex.test(line)) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scans directories and outputs a list of found paths that matches the regex
|
||||||
|
*
|
||||||
|
* @param {string} directory The starting directory
|
||||||
|
* @param {RegExp} regex The search regex
|
||||||
|
* @param {boolean} recursive Enables recursion
|
||||||
|
* @returns Array<string>
|
||||||
|
*/
|
||||||
|
exports.scanDirectory = function (directory, regex, recursive) {
|
||||||
|
let output = [];
|
||||||
|
|
||||||
|
if (fs.existsSync(directory)) {
|
||||||
|
const items = fs.readdirSync(directory);
|
||||||
|
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const item = items[i];
|
||||||
|
const itemPath = path.join(directory, item);
|
||||||
|
const stats = fs.statSync(itemPath);
|
||||||
|
|
||||||
|
if (regex.test(itemPath)) {
|
||||||
|
output.push(itemPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
if (recursive) {
|
||||||
|
output = output.concat(exports.scanDirectory(itemPath, regex, recursive));
|
||||||
|
} else {
|
||||||
|
// Move onto the next item
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
};
|
||||||
@@ -19,17 +19,17 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var log = require('./lib/log'),
|
var log = require('./lib/log');
|
||||||
reqs = require('./lib/check_reqs'),
|
var reqs = require('./lib/check_reqs');
|
||||||
args = process.argv;
|
var args = process.argv;
|
||||||
|
|
||||||
// Usage support for when args are given
|
// Usage support for when args are given
|
||||||
if(args.length > 2) {
|
if (args.length > 2) {
|
||||||
log.help();
|
log.help();
|
||||||
} else {
|
} else {
|
||||||
reqs.run().done(function() {
|
reqs.run().then(function () {
|
||||||
return log.run();
|
return log.run();
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
console.error('ERROR: ' + err);
|
console.error('ERROR: ' + err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,22 +24,23 @@ var nopt = require('nopt');
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
// Support basic help commands
|
// Support basic help commands
|
||||||
if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0)
|
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
|
||||||
require('./lib/run').help();
|
require('./lib/run').help();
|
||||||
|
}
|
||||||
|
|
||||||
// Do some basic argument parsing
|
// Do some basic argument parsing
|
||||||
var runOpts = nopt({
|
var runOpts = nopt({
|
||||||
'verbose' : Boolean,
|
verbose: Boolean,
|
||||||
'silent' : Boolean,
|
silent: Boolean,
|
||||||
'debug' : Boolean,
|
debug: Boolean,
|
||||||
'release' : Boolean,
|
release: Boolean,
|
||||||
'nobuild': Boolean,
|
nobuild: Boolean,
|
||||||
'buildConfig' : path,
|
buildConfig: path,
|
||||||
'archs' : String,
|
archs: String,
|
||||||
'device' : Boolean,
|
device: Boolean,
|
||||||
'emulator': Boolean,
|
emulator: Boolean,
|
||||||
'target' : String
|
target: String
|
||||||
}, { 'd' : '--verbose' });
|
}, { d: '--verbose' });
|
||||||
|
|
||||||
// Make runOptions compatible with PlatformApi run method spec
|
// Make runOptions compatible with PlatformApi run method spec
|
||||||
runOpts.argv = runOpts.argv.remain;
|
runOpts.argv = runOpts.argv.remain;
|
||||||
@@ -47,7 +48,7 @@ runOpts.argv = runOpts.argv.remain;
|
|||||||
require('./loggingHelper').adjustLoggerLevel(runOpts);
|
require('./loggingHelper').adjustLoggerLevel(runOpts);
|
||||||
|
|
||||||
new Api().run(runOpts)
|
new Api().run(runOpts)
|
||||||
.catch(function(err) {
|
.catch(function (err) {
|
||||||
console.error(err, err.stack);
|
console.error(err, err.stack);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Coho updates this line:
|
const Api = require('./Api');
|
||||||
var VERSION = "7.1.0";
|
|
||||||
|
|
||||||
module.exports.version = VERSION;
|
console.log(Api.version());
|
||||||
|
|
||||||
if (!module.parent) {
|
|
||||||
console.log(VERSION);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
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"
|
||||||
package="__PACKAGE__" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
|
package="__PACKAGE__" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:largeScreens="true"
|
android:largeScreens="true"
|
||||||
@@ -30,20 +30,18 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application android:icon="@mipmap/icon" android:label="@string/app_name"
|
<application android:icon="@mipmap/ic_launcher" 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="@android:style/Theme.DeviceDefault.NoActionBar"
|
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode">
|
||||||
<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="19" android:targetSdkVersion="__APILEVEL__"/>
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -19,36 +19,84 @@
|
|||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
apply from: '../CordovaLib/cordova.gradle'
|
||||||
|
|
||||||
|
if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||||
|
String defaultGradlePluginKotlinVersion = kotlin_version
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the user's defined Kotlin Version from config.xml.
|
||||||
|
* If the version is not set or invalid, it will default to the ${defaultGradlePluginKotlinVersion}
|
||||||
|
*/
|
||||||
|
String gradlePluginKotlinVersion = cdvHelpers.getConfigPreference('GradlePluginKotlinVersion', defaultGradlePluginKotlinVersion)
|
||||||
|
if(!cdvHelpers.isVersionValid(gradlePluginKotlinVersion)) {
|
||||||
|
println("The defined Kotlin version (${gradlePluginKotlinVersion}) does not appear to be a valid version. Falling back to version: ${defaultGradlePluginKotlinVersion}.")
|
||||||
|
gradlePluginKotlinVersion = defaultGradlePluginKotlinVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change the version to be used.
|
||||||
|
ext.kotlin_version = gradlePluginKotlinVersion
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
|
||||||
url "https://maven.google.com"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
apply from: '../CordovaLib/cordova.gradle'
|
||||||
|
|
||||||
|
classpath 'com.android.tools.build:gradle:4.0.0'
|
||||||
|
|
||||||
|
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) {
|
||||||
|
String defaultGradlePluginGoogleServicesVersion = '4.2.0'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the user's defined Google Services Plugin Version from config.xml.
|
||||||
|
* If the version is not set or invalid, it will default to the ${defaultGradlePluginGoogleServicesVersion}
|
||||||
|
*/
|
||||||
|
String gradlePluginGoogleServicesVersion = cdvHelpers.getConfigPreference('GradlePluginGoogleServicesVersion', defaultGradlePluginGoogleServicesVersion)
|
||||||
|
if(!cdvHelpers.isVersionValid(gradlePluginGoogleServicesVersion)) {
|
||||||
|
println("The defined Google Services plugin version (${gradlePluginGoogleServicesVersion}) does not appear to be a valid version. Falling back to version: ${defaultGradlePluginGoogleServicesVersion}.")
|
||||||
|
gradlePluginGoogleServicesVersion = defaultGradlePluginGoogleServicesVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the Google Services classpath and set it.
|
||||||
|
String gradlePluginGoogleServicesClassPath = "com.google.gms:google-services:${gradlePluginGoogleServicesVersion}"
|
||||||
|
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 {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral();
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
gradleVersion = '4.1.0'
|
gradleVersion = '6.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
// The value for android.compileSdkVersion.
|
||||||
if (!project.hasProperty('cdvCompileSdkVersion')) {
|
if (!project.hasProperty('cdvCompileSdkVersion')) {
|
||||||
cdvCompileSdkVersion = null;
|
cdvCompileSdkVersion = null;
|
||||||
@@ -65,11 +113,19 @@ ext {
|
|||||||
if (!project.hasProperty('cdvMinSdkVersion')) {
|
if (!project.hasProperty('cdvMinSdkVersion')) {
|
||||||
cdvMinSdkVersion = null
|
cdvMinSdkVersion = null
|
||||||
}
|
}
|
||||||
|
// Sets the maxSdkVersion to the given value.
|
||||||
|
if (!project.hasProperty('cdvMaxSdkVersion')) {
|
||||||
|
cdvMaxSdkVersion = null
|
||||||
|
}
|
||||||
|
// The value for android.targetSdkVersion.
|
||||||
|
if (!project.hasProperty('cdvTargetSdkVersion')) {
|
||||||
|
cdvTargetSdkVersion = 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
|
||||||
}
|
}
|
||||||
// Whether to append a 0 "abi digit" to versionCode when only a single APK is build
|
// Whether to append a 0 "abi digit" to versionCode when only a single APK is build
|
||||||
if (!project.hasProperty('cdvVersionCodeForceAbiDigit')) {
|
if (!project.hasProperty('cdvVersionCodeForceAbiDigit')) {
|
||||||
cdvVersionCodeForceAbiDigit = null
|
cdvVersionCodeForceAbiDigit = null
|
||||||
}
|
}
|
||||||
@@ -93,16 +149,23 @@ ext {
|
|||||||
// PLUGIN GRADLE EXTENSIONS START
|
// PLUGIN GRADLE EXTENSIONS START
|
||||||
// PLUGIN GRADLE EXTENSIONS END
|
// PLUGIN GRADLE EXTENSIONS END
|
||||||
|
|
||||||
def hasBuildExtras = file('build-extras.gradle').exists()
|
def hasBuildExtras1 = file('build-extras.gradle').exists()
|
||||||
if (hasBuildExtras) {
|
if (hasBuildExtras1) {
|
||||||
apply from: 'build-extras.gradle'
|
apply from: 'build-extras.gradle'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set property defaults after extension .gradle files.
|
def hasBuildExtras2 = file('../build-extras.gradle').exists()
|
||||||
if (ext.cdvCompileSdkVersion == null) {
|
if (hasBuildExtras2) {
|
||||||
ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
|
apply from: '../build-extras.gradle'
|
||||||
//ext.cdvCompileSdkVersion = project.ext.defaultCompileSdkVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set property defaults after extension .gradle files.
|
||||||
|
ext.cdvCompileSdkVersion = cdvCompileSdkVersion == null ? (
|
||||||
|
defaultCompileSdkVersion == null
|
||||||
|
? privateHelpers.getProjectTarget()
|
||||||
|
: defaultCompileSdkVersion
|
||||||
|
) : Integer.parseInt('' + cdvCompileSdkVersion);
|
||||||
|
|
||||||
if (ext.cdvBuildToolsVersion == null) {
|
if (ext.cdvBuildToolsVersion == null) {
|
||||||
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
|
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
|
||||||
//ext.cdvBuildToolsVersion = project.ext.defaultBuildToolsVersion
|
//ext.cdvBuildToolsVersion = project.ext.defaultBuildToolsVersion
|
||||||
@@ -117,7 +180,14 @@ 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
|
|
||||||
|
// minSdkVersion, maxSdkVersion and targetSdkVersion
|
||||||
|
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? defaultMinSdkVersion : Integer.parseInt('' + cdvMinSdkVersion)
|
||||||
|
if (cdvMaxSdkVersion != null) {
|
||||||
|
ext.cdvMaxSdkVersion = Integer.parseInt('' + cdvMaxSdkVersion)
|
||||||
|
}
|
||||||
|
ext.cdvTargetSdkVersion = cdvTargetSdkVersion == null ? defaultTargetSdkVersion : Integer.parseInt('' + cdvTargetSdkVersion)
|
||||||
|
|
||||||
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
|
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
|
||||||
|
|
||||||
def computeBuildTargetName(debugBuild) {
|
def computeBuildTargetName(debugBuild) {
|
||||||
@@ -140,24 +210,27 @@ cdvBuildRelease.dependsOn {
|
|||||||
return computeBuildTargetName(false)
|
return computeBuildTargetName(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
task cdvPrintProps << {
|
task cdvPrintProps {
|
||||||
println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
|
doLast {
|
||||||
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
|
println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
|
||||||
println('cdvVersionCode=' + cdvVersionCode)
|
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
|
||||||
println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
|
println('cdvVersionCode=' + cdvVersionCode)
|
||||||
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
|
println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
|
||||||
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
|
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
|
||||||
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
|
println('cdvMaxSdkVersion=' + cdvMaxSdkVersion)
|
||||||
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
|
println('cdvTargetSdkVersion=' + cdvTargetSdkVersion)
|
||||||
println('cdvBuildArch=' + cdvBuildArch)
|
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
|
||||||
println('computedVersionCode=' + android.defaultConfig.versionCode)
|
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
|
||||||
android.productFlavors.each { flavor ->
|
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
|
||||||
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
|
println('cdvBuildArch=' + cdvBuildArch)
|
||||||
|
println('computedVersionCode=' + android.defaultConfig.versionCode)
|
||||||
|
android.productFlavors.each { flavor ->
|
||||||
|
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
|
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
|
||||||
applicationId privateHelpers.extractStringFromManifest("package")
|
applicationId privateHelpers.extractStringFromManifest("package")
|
||||||
@@ -165,6 +238,14 @@ android {
|
|||||||
if (cdvMinSdkVersion != null) {
|
if (cdvMinSdkVersion != null) {
|
||||||
minSdkVersion cdvMinSdkVersion
|
minSdkVersion cdvMinSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cdvMaxSdkVersion != null) {
|
||||||
|
maxSdkVersion cdvMaxSdkVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cdvTargetSdkVersion != null) {
|
||||||
|
targetSdkVersion cdvTargetSdkVersion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
@@ -174,10 +255,11 @@ android {
|
|||||||
compileSdkVersion cdvCompileSdkVersion
|
compileSdkVersion cdvCompileSdkVersion
|
||||||
buildToolsVersion cdvBuildToolsVersion
|
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 Android Manifest by 10 and
|
// By default, we multiply the existing version code in the
|
||||||
//add a number for each architecture. If you are not using Crosswalk or SQLite, you can
|
// Android Manifest by 10 and add a number for each architecture.
|
||||||
//ignore this chunk of code, and your version codes will be respected.
|
// If you are not using Crosswalk or SQLite, you can
|
||||||
|
// ignore this chunk of code, and your version codes will be respected.
|
||||||
|
|
||||||
if (Boolean.valueOf(cdvBuildMultipleApks)) {
|
if (Boolean.valueOf(cdvBuildMultipleApks)) {
|
||||||
flavorDimensions "default"
|
flavorDimensions "default"
|
||||||
@@ -243,9 +325,14 @@ 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'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -257,6 +344,11 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||||
|
|
||||||
|
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$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"))
|
||||||
@@ -322,3 +414,7 @@ for (def func : cdvPluginPostBuildExtras) {
|
|||||||
if (hasProperty('postBuildExtras')) {
|
if (hasProperty('postBuildExtras')) {
|
||||||
postBuildExtras()
|
postBuildExtras()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) {
|
||||||
|
apply plugin: 'com.google.gms.google-services'
|
||||||
|
}
|
||||||
|
|||||||
@@ -102,13 +102,13 @@ h1 {
|
|||||||
50% { opacity: 0.4; }
|
50% { opacity: 0.4; }
|
||||||
to { opacity: 1.0; }
|
to { opacity: 1.0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@-webkit-keyframes fade {
|
@-webkit-keyframes fade {
|
||||||
from { opacity: 1.0; }
|
from { opacity: 1.0; }
|
||||||
50% { opacity: 0.4; }
|
50% { opacity: 0.4; }
|
||||||
to { opacity: 1.0; }
|
to { opacity: 1.0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.blink {
|
.blink {
|
||||||
animation:fade 3000ms infinite;
|
animation:fade 3000ms infinite;
|
||||||
-webkit-animation:fade 3000ms infinite;
|
-webkit-animation:fade 3000ms infinite;
|
||||||
|
|||||||
@@ -19,33 +19,31 @@
|
|||||||
// 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 {
|
||||||
|
ext.kotlin_version = '1.3.50'
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
|
||||||
url "https://maven.google.com"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:4.0.0'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$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.1'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
|
||||||
url "https://maven.google.com"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//This replaces project.properties w.r.t. build settings
|
//This replaces project.properties w.r.t. build settings
|
||||||
project.ext {
|
project.ext {
|
||||||
defaultBuildToolsVersion="27.0.1" //String
|
defaultBuildToolsVersion="29.0.2" //String
|
||||||
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
|
defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1
|
||||||
defaultTargetSdkVersion=27 //Integer - We ALWAYS target the latest by default
|
defaultTargetSdkVersion=29 //Integer - We ALWAYS target the latest by default
|
||||||
defaultCompileSdkVersion=27 //Integer - We ALWAYS compile with the latest by default
|
defaultCompileSdkVersion=29 //Integer - We ALWAYS compile with the latest by default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,12 @@ ant-gen
|
|||||||
# Eclipse builds
|
# Eclipse builds
|
||||||
gen
|
gen
|
||||||
out
|
out
|
||||||
# Gradle builds
|
# Gradle build artifacts
|
||||||
|
.gradle
|
||||||
|
.gradletasknamecache
|
||||||
/build
|
/build
|
||||||
|
/CordovaLib/build
|
||||||
|
/app/build
|
||||||
|
gradle-app.setting
|
||||||
|
# Android Studio
|
||||||
|
.idea
|
||||||
|
|||||||
@@ -1,311 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 286 KiB After Width: | Height: | Size: 190 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 292 KiB After Width: | Height: | Size: 192 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@mipmap/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
|
After Width: | Height: | Size: 86 B |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@mipmap/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
|
After Width: | Height: | Size: 83 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |