忍者ブログ
  • 2024.03
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 2024.05
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/04/28 19:16 】 |
BuildVariants

参考ページ
build.gradleへの記述でビルドを分けられる。

Build Types
debug,releaseなどを指定できる
書き方例。上記ページから引用

android {
buildTypes {
debug {
packageNameSuffix ".debug"
}

inhouse.initWith(buildTypes.release)
inhouse {
packageNameSuffix ".inhouse"
}
}
}



Product Flavors
ビルドレベルではなく、機能の違いなどを指定できる
書き方例。上記ページから引用

android {

productFlavors {
/* 有料版 */
pro {
packageName "info.vividcode.android.app.pfsample.pro"
}

/* 無料版 */
free {
packageName "info.vividcode.android.app.pfsample.free"
}
}
}



C++のようにマクロはないので、ソースの切り替えは2種類用意する。
app/src/flavor1/
app/src/flavor2/
のように、build.gradle に書いたflavor名のディレクトリ以下に配置したら、それが使用されるということらしい。(まだ試していない)


Build TypesとProduct Flavorを合わせて Build Variants という。
どのBuild Variantsでビルドするかは、以下の場所で指定する。

結構気づきにくい
PR
【2016/03/08 15:28 】 | Android | 有り難いご意見(0)
ProGuardまとめ
Android公式ドキュメント
Proguard公式ドキュメント2

ProGuardがやること
・不要なコードの削除
・変数名、クラス名を変更して、難読化する

・リリースモードでのみ動作
・特に何もせずとも処理されるようになっている

・build.gradleに設定記述あり


android {
...

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}



minifyEnabled を true にすると、ProGuardが実行される

proguardFiles getDefaultProguardFile('proguard-android.txt'),
行は、proguardの詳細設定が描いてあるファイル名を指定。
ANDROID_SDK_ROOT/tools/proguard/ 以下のファイル名を指定する。
proguard-android.txt
の他に、最適化を含んだ設定ファイルとして
proguard-android-optimize.txt
というものも設定できるようだ。

ちなみに2つのファイルの差分は以下だけ

proguard-android.txt(最適化なし)

-dontoptimize
-dontpreverify



proguard-android-optimize.txt(最適化あり)

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify



多く書いてあるのは、メソッドを削除させないようにする設定。例えば

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}


のようなもの。Javaコード上では使われていないが、xmlから呼び出すために必要なメソッド、のようなことらしい



さて、build.gradleの記述に戻る
'proguard-rules.pro'
と書いてある行があるが、これはプロジェクトディレクトリ内にあり、
プロジェクト固有の設定を書くファイル。(proはprojectのことのようだ)



また、ProGuard処理をすると、
build/outs/mapping.txt
というファイルが生成される。
これを使うと、難読化したスタックトレースを元に戻すことができる。
$ cd $ANDROID_SDK_ROOT/tools/proguard
$ retrace.bat -verbose mapping.txt obfuscated_trace.txt


さて、実際にやってみたところ、エラーが出た


調べると、結局proguard-rules.proに

-dontwarn
-ignorewarnings


と書けということになりそう。


詳しいページ
これ見ると、JNIだといろいろ設定がいるとのこと。
おそらく、javaコード内から呼び出されることのない、Native_***()系メソッドを全部keep指定する必要があるということだろう。

-keepclasseswithmembers class MainActivity {
public static ;
}


という感じか?(試していないので合っているかはわからない)


処理にもものすごい時間が掛かる。
しばらくやらなくていいかなという気がしてくる
【2016/03/08 15:11 】 | Android | 有り難いご意見(0)
Androidでpushwoosh実装
Qiita
【2016/02/29 12:54 】 | Android | 有り難いご意見(0)
AndroidでAnalytics実装
公式ページ
Qiitaの記事

設定ファイルを作るページ
このjsonをapp/以下に配置する

xmlは
app/src/main/res/xml/app_tracker.xml
にある。ここにトラッカーIDなど記述する
app/res/xml/
ではないことに注意。

【2016/02/26 18:05 】 | Android | 有り難いご意見(0)
Javaのスレッド名を表示する方法
以下がスレッド名

Thread.currentThread().getName()


あまり関係ないが、スレッドで参考になるページー>ここ
【2016/02/25 18:03 】 | Android | 有り難いご意見(0)
androidのファイラ
アプリの外部ストレージにファイルを保存した時とか、
ちゃんとファイルがあるか調べたい時など。

$ adb shell
$ run-as パッケージ名

でok.


一応、AndroidStudioで
Tools -> Android -> Android Device Monitor
というものもあるが、権限がなかったりであまり中が見えないので使いにくい
【2016/02/24 15:57 】 | Android | 有り難いご意見(0)
AndroidStudioでライブラリを追加するには
標準の(公式の)ライブラリを追加するのは簡単。

Project Structure → プロジェクトを選択 → Dependencies タブを選択 → 左下の「+」を選択 → Library Dependencies を選択

で、欲しいライブラリを選択する。これだけで良い。
もうソースでimportできるようになる


それ以外のライブラリを追加する場合は、
libs/ ディレクトリに .jar ファイルを置く。
それからProject Structure 以下同じ手順を進み、
File Dependencies を選択すると、libs/ ディレクトリにあるファイルが選べるようになっている。


いずれの場合も、build.gradleにもその記述ができることを確認する。



なお、libs/ ディレクトリに追加したのに、build.gradleにないファイルがあると、
コンパイル時に

java.lang.RuntimeException: Exception parsing classes


というエラーになる。

【2016/02/23 20:08 】 | Android | 有り難いご意見(0)
cocos2d-x + Androidで、どのスタティックライブラリを使うべきか
実機に転送して、実行しようとした時、以下のエラーが出る

java.lang.UnsatisfiedLinkError: dlopen failed: unknown reloc type 160

調べたところ、スタティックライブラリをc++_staticにしていることが原因らしい。
cocos2d_libとc++_staticの相性の問題のようだ。困ったものだ

参考

デフォでは、gnustl_static を指定しているのだが(cocosプロジェクトが作られた時もそうなっている)、
gnustl_staticは以下のようなメソッドが使えない(コンパイルエラーになる)
std::to_string
std::stol
std::stoul
std::stoll
std::stoull
std::stof
std::stod

これはndkの怠慢じゃないかと思うのだが、ともかく
こちらを立てればあちらが立たずの状態になっている。


仕方ないので、
gnustl_staticを使用し、
std::文字列系の処理を自前で実装することにする。

実装は以下のとおり

AndroidHelper.h

#ifndef AndroidHelper_h
#define AndroidHelper_h

#include
#include
#include

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

namespace std{

template
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}

int stoi (const std::string& __str, size_t* __idx = 0, int __base = 10);
long stol (const std::string& __str, size_t* __idx = 0, int __base = 10);
unsigned long stoul (const std::string& __str, size_t* __idx = 0, int __base = 10);
long long stoll (const std::string& __str, size_t* __idx = 0, int __base = 10);
unsigned long long stoull(const std::string& __str, size_t* __idx = 0, int __base = 10);
float stof (const std::string& __str, size_t* __idx = 0);
double stod (const std::string& __str, size_t* __idx = 0);

}

#endif

#endif






AndroidHelper.cpp

#include
#include

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

namespace std{

int stoi (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
int x = (int)strtol(p, &end, __base); //strtoiというのはない
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

long stol (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
long x = strtol(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

unsigned long stoul (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
unsigned long x = strtoul(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

long long stoll (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
long long x = strtoll(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

unsigned long long stoull(const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
unsigned long long x = strtoull(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

float stof (const std::string& __str, size_t* __idx)
{
const char* p = __str.c_str();
char* end;
float x = strtof(p, &end);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

double stod (const std::string& __str, size_t* __idx)
{
const char* p = __str.c_str();
char* end;
double x = strtod(p, &end);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

}

#endif
【2016/02/22 17:13 】 | Android | 有り難いご意見(0)
AndroidStudioでのgitignore

gitignore参考


#AndroidStudio
.gradle/
local.properties

#IntelliJ IDEA project files
.idea/
*.ipr
*.iml

build/
/captures
【2016/02/21 17:01 】 | Android | 有り難いご意見(0)
gradleでエラーが
前の記事のように記述してビルドしたところ、実機で実行時にエラーが発生

Cannot load library: reloc_library[1285]: cannot locate 'rand'
参考

原因は、API-21(Android5.0)でコンパイルしたアプリを、API-20以下の端末で実行したことらしい


謎だ
【2016/02/21 17:00 】 | Android | 有り難いご意見(0)
<<前ページ | ホーム | 次ページ>>