2016年11月9日水曜日

Android Studio への移行

eclipseからAndroid Studioにインポートした時以下のエラーが発生



Error:(1, 1) エラー: '\ufeff'は不正な文字です

エラーが発生しているファイルを開き、サクラエディタなどで開き、BOMのチェックを外し保存する



ndk-build 編


Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
 https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
 http://tools.android.com/tech-docs/new-build-system/gradle-experimental.


プロジェクト名をaaaとした場合、以下のようにトップディレクトリに「gradle.properties」ファイルを作成。
ファイルを作成すると自動的にsyncされ(syncされなければSyncボタンを押す)、以下のように表示される。
そのファイルに、「android.useDeprecatedNdk=true」と記述。




Error:Execution failed for task ':app:compileDebugNdk'.
> NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\\ndk rather than C:\ndk)


NDKをインストール



参考
https://developer.android.com/ndk/index.html
https://developer.android.com/ndk/guides/index.html




To install:
- LLDB 2.2 (lldb;2.2)
- CMake 3.6.3155560 (cmake;3.6.3155560)

Preparing "Install LLDB 2.2".
Downloading https://dl.google.com/android/repository/lldb-2.2.3271982-windows.zip
"Install LLDB 2.2" ready.
Preparing "Install CMake 3.6.3155560".
Downloading https://dl.google.com/android/repository/cmake-3.6.3155560-windows-x86_64.zip
"Install CMake 3.6.3155560" ready.
Finishing "Install LLDB 2.2"
Installing LLDB 2.2 in D:\android\androidStudio\sdk\lldb\2.2
"Install LLDB 2.2" complete.
Finishing "Install CMake 3.6.3155560"
Installing CMake 3.6.3155560 in D:\android\androidStudio\sdk\cmake\3.6.3155560
"Install CMake 3.6.3155560" complete.



Error:(12, 10) 'string' file not found





build.gradle(Module:app)


android {
    compileSdkVersion 19    buildToolsVersion "24.0.1"
    defaultConfig {
        applicationId "XXXXXXXXXXXXXXXXXXXXX"        minSdkVersion 19        targetSdkVersion 19        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7            targetCompatibility JavaVersion.VERSION_1_7        }

        ndk {
            moduleName "XXXXXXXXXX" 
            stl     = "stlport_static"    ← ここに追加
        }
    }



注意:D:\git\xxxxx\xxxx.javaの操作は、未チェックまたは安全ではありません。
注意:詳細は、-Xlint:uncheckedオプションを指定して再コンパイルしてください。




allprojects {
    repositories {
        jcenter()
    }
    // ↓↓↓ 水色部分を追加

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"        }
    }
}




Error:(933, 66) 警告: [unchecked] 無検査変換
期待値: ArrayList<ViewId.RadioGrpCtrId>
検出値:    ArrayList




 CMake 編



先ほど追加した「gradle.properties」の「android.useDeprecatedNdk=true」は一旦削除し、「org.gradle.jvmargs=-Xmx1536m」を追加する


CMakeLists.txt 作成




serviceが起動しない件

サービスが動かない。最近のバージョン6とかでは?
色々調べて判った事として、Activityなしだと無いサービスが動かない、今までは動いていたが。


アプリが起動していない状態になっている
FLAG_INCLUDE_STOPPED_PACKAGES
FLAG_EXCLUDE_STOPPED_PACKAGES

アプリをインストールして、なおかつ一回も起動していない場合は、FLAG_EXCLUDE_STOPPED_PACKAGESとなっている模様です。


昔は、以下のエラーが起こっても動いていたが動かなくなっている。今のばーじょんでは?
[2016-11-11 15:15:14 - xxxx] No Launcher activity found!
[2016-11-11 15:15:14 - xxxx] The launch will only sync the application package on the device!


ActivityなしだとFLAG_EXCLUDE_STOPPED_PACKAGESの状態で、バックグラウンドのサービスが動かない
解決するには、インストール後一度でも良いので、Activityを起動させる


参考アドレス


http://www.reinon.net/2016/05/android-studio-21-ndk.html
http://stackoverflow.com/questions/16667903/android-studio-gradle-and-ndk
http://keiji.github.io/farewell-adt-book/archives/farewell-adt.pdf

0 件のコメント:

コメントを投稿