13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cordova でのスマホアプリ開発

Last updated at Posted at 2019-07-19

環境構築

https://ionicframework.com/jp/docs/installation/cli
https://cordova.apache.org/docs/ja/9.x/guide/cli/index.html

nodejs のインストール

npm で cordova 、ionic のインストールを行うため nodejs をインストールする

cordova のインストール
C:\>
C:\>npm install -g cordova
C:\\AppData\Roaming\npm\cordova -> C:\\AppData\Roaming\npm\node_modules\cordova\bin\cordova
+ cordova@9.0.0
added 453 packages from 356 contributors in 29.208s

C:\>
アプリケーションの作成
C:\cordova_app>cordova create hello com.example.hello HelloWorld
Creating a new cordova project.

C:\cordova_app>
C:\cordova_app>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は E607-7688 です

 C:\cordova_app のディレクトリ

2019/07/05  10:49    <DIR>          .
2019/07/05  10:49    <DIR>          ..
2019/07/05  10:49    <DIR>          hello
               0 個のファイル                   0 バイト
               3 個のディレクトリ  126,528,647,168 バイトの空き領域

C:\cordova_app>

作成したプロジェクトの環境を確認

C:\cordova_app>cd hello

C:\cordova_app\hello>cordova platforms ls
Installed platforms:

Available platforms:
  android ^8.0.0
  browser ^6.0.0
  electron ^1.0.0
  ios ^5.0.0
  osx ^5.0.0
  windows ^7.0.0

C:\cordova_app\hello>
アプリケーションのビルド
C:\cordova_app\hello>cordova build android
No platforms added to this project. Please use `cordova platform add <platform>`.

C:\cordova_app\hello>

プラットフォームを追加しなさいと怒られるので、android を追加

C:\cordova_app\hello>
C:\cordova_app\hello>cordova platform add android
Using cordova-fetch for cordova-android@^8.0.0
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.example.hello
        Name: HelloWorld
        Activity: MainActivity
        Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@8.0.0
Plugin 'cordova-plugin-whitelist' found in config.xml... Migrating it to package.json
Discovered saved plugin "cordova-plugin-whitelist". Adding it to the project
Installing "cordova-plugin-whitelist" for android
Adding cordova-plugin-whitelist to package.json

C:\cordova_app\hello>
C:\cordova_app\hello>cordova platforms ls
Installed platforms:
  android 8.0.0
Available platforms:
  browser ^6.0.0
  electron ^1.0.0
  ios ^5.0.0
  osx ^5.0.0
  windows ^7.0.0

C:\cordova_app\hello>

再度ビルド

C:\cordova_app\hello>cordova build android
Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.

C:\cordova_app\hello>

ANDROID_HOME、並びに android のコマンドパスが無いよと怒られる

プラットフォームとは別に android の SDK を別途用意する必要があるらしい

※ios 用だと mac がないとだめだとかなんとか...

Android Studio のインストール

しました。

環境変数を追加
ANDROID_HOME:
C:\Users\****\AppData\Local\Android\Sdk

JAVA_HOME:
C:\Program Files\Android\Android Studio\jre

アプリケーションのビルド2回目
C:\>cd C:\cordova_app\hello
C:\cordova_app\hello>cordova build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\****\AppData\Local\Android\Sdk (DEPRECATED)

Welcome to Gradle 5.1.1!

Here are the highlights of this release:
 - Control which dependencies can be retrieved from which repositories
 - Production-ready configuration avoidance APIs

For more details see https://docs.gradle.org/5.1.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 11s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-4.10.3-all.zip
................................................................................................................

Welcome to Gradle 4.10.3!

Here are the highlights of this release:
 - Incremental Java compilation by default
 - Periodic Gradle caches cleanup
 - Gradle Kotlin DSL 1.0-RC6
 - Nested included builds
 - SNAPSHOT plugin versions in the `plugins {}` block

For more details see https://docs.gradle.org/4.10.3/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
File C:\Users\****\.android\repositories.cfg could not be loaded.
Checking the license for package Android SDK Platform 28 in C:\Users\****\AppData\Local\Android\Sdk\licenses
Warning: License for package Android SDK Platform 28 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     platforms;android-28 Android SDK Platform 28
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: C:\Users\****\AppData\Local\Android\Sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 25s
C:\cordova_app\hello\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     platforms;android-28 Android SDK Platform 28
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: C:\Users\****\AppData\Local\Android\Sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 25s

C:\cordova_app\hello>

Android SDK の licences が have not been accepted だとかなんとか

Android SDK Platform 28 のライセンスを accepted するぽい

ので、してみた。

Android Studio の Configure から SDK Manager を選択
Android 9.0(Pie) API Level:28 をインストール

アプリケーションのビルド3回目
C:\cordova_app\hello>
C:\cordova_app\hello>cordova build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\\****\AppData\Local\Android\Sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest
> Task :CordovaLib:processDebugManifest
> Task :app:preDebugBuild
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript
> Task :app:checkDebugManifest
> Task :app:generateDebugBuildConfig
> Task :app:prepareLintJar
> Task :app:generateDebugSources
> Task :CordovaLib:compileDebugRenderscript
> Task :CordovaLib:generateDebugBuildConfig
> Task :CordovaLib:generateDebugResValues
> Task :CordovaLib:generateDebugResources
> Task :CordovaLib:packageDebugResources
> Task :CordovaLib:generateDebugRFile
> Task :CordovaLib:prepareLintJar
> Task :CordovaLib:generateDebugSources
> Task :CordovaLib:javaPreCompileDebug

????:C:\cordova_app\hello\platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemCookieManager.java??????API???g?p?????I?[?o?[???C?h?????????B
????:????A-Xlint:deprecation?I?v?V???????w?????R???p?C??????????????B
> Task :CordovaLib:compileDebugJavaWithJavac

> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
> Task :app:javaPreCompileDebug
> Task :app:mainApkListPersistenceDebug
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:mergeDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:processDebugManifest
> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac
> Task :app:compileDebugNdk NO-SOURCE
> Task :app:compileDebugSources
> Task :app:mergeDebugShaders
> Task :app:compileDebugShaders
> Task :app:generateDebugAssets
> Task :CordovaLib:mergeDebugShaders
> Task :CordovaLib:compileDebugShaders
> Task :CordovaLib:generateDebugAssets
> Task :CordovaLib:packageDebugAssets
> Task :app:mergeDebugAssets
> Task :app:validateSigningDebug
> Task :app:signingConfigWriterDebug
> Task :app:transformClassesWithDexBuilderForDebug
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug
> Task :app:transformDexArchiveWithDexMergerForDebug
> Task :app:mergeDebugJniLibFolders
> Task :CordovaLib:compileDebugNdk NO-SOURCE
> Task :CordovaLib:mergeDebugJniLibFolders
> Task :CordovaLib:transformNativeLibsWithMergeJniLibsForDebug
> Task :CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug
> Task :app:transformNativeLibsWithMergeJniLibsForDebug
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:transformResourcesWithMergeJavaResForDebug
> Task :app:packageDebug
> Task :app:assembleDebug
> Task :app:cdvBuildDebug

BUILD SUCCESSFUL in 31s
42 actionable tasks: 42 executed
Built the following apk(s):
        C:\cordova_app\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk

C:\cordova_app\hello>

わっほい

エミュレータでの動作確認

Android Studio の Configure から AVD Manager を選択
適当な機種を選択してインストール

...デキマセン

HAMX のインストールで失敗する

※対応は色々ある様子
 とりあえず Windows の機能の有効かまたは無効化 からHyper-V を無効化するとインストールできるようになった
 (要再起動

エミュレータを起動しておいて、 cordova を実行

C:\>cd C:\cordova_app\hello
C:\cordova_app\hello>cordova run android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\****\AppData\Local\Android\Sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE
> Task :app:compileDebugJavaWithJavac UP-TO-DATE
> Task :app:compileDebugNdk NO-SOURCE
> Task :app:compileDebugSources UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders UP-TO-DATE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :CordovaLib:mergeDebugShaders UP-TO-DATE
> Task :CordovaLib:compileDebugShaders UP-TO-DATE
> Task :CordovaLib:generateDebugAssets UP-TO-DATE
> Task :CordovaLib:packageDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:signingConfigWriterDebug UP-TO-DATE
> Task :app:transformClassesWithDexBuilderForDebug UP-TO-DATE
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug UP-TO-DATE
> Task :app:transformDexArchiveWithDexMergerForDebug UP-TO-DATE
> Task :app:mergeDebugJniLibFolders UP-TO-DATE
> Task :CordovaLib:compileDebugNdk NO-SOURCE
> Task :CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE
> Task :app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
> Task :app:packageDebug UP-TO-DATE
> Task :app:assembleDebug UP-TO-DATE
> Task :app:cdvBuildDebug UP-TO-DATE

BUILD SUCCESSFUL in 2s
42 actionable tasks: 42 up-to-date
Built the following apk(s):
        C:\cordova_app\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\****\AppData\Local\Android\Sdk (DEPRECATED)
No target specified and no devices found, deploying to emulator
Using apk: C:\cordova_app\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Package name: com.example.hello
INSTALL SUCCESS
LAUNCH SUCCESS

C:\cordova_app\hello>

test_cordova_run.png

起動したぽい

cordova でのスマホアプリ開発 2

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?