2013-07-12 5 views
11

私は最近、自分のデバイスを頻繁に改造するrootユーザーのためにこれをapplicationにしました。アプリケーションのインストールサイズは電話でどのように変化しますか?

今、私はアプリケーションのインストールサイズで非常に奇妙な動作に気付きました。

XMLファイルからビューを初期化して通常のアクティビティを使用したとき、サイズは715 kbでした。

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.main_layout); 
    executeEvents = new ExecuteEvents(this); 
    display = (TextView) findViewById(R.id.display); 
    powermenu = (Button) findViewById(R.id.powermenu); 
    turnoffscreen = (Button) findViewById(R.id.turnscreenoff); 
    mapButton = (ImageButton) findViewById(R.id.mapButton); 
    SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS); 
    if(SP.contains(PBConstants.INPUT_DEVICE_TAG)) 
     display.setText(getResources().getString(R.string.configured)); 
    mapButton.setOnClickListener(this); 
    powermenu.setOnClickListener(this); 
    turnoffscreen.setOnClickListener(this); 
} 

私が作成したダイアログに切り替えた後、XMLファイルのウィジェットを含むビューを設定しました。アプリのサイズは200kbになりました。私はこれを使用する場合

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    //setContentView(R.layout.main_layout); 
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.main_layout, null); 
    executeEvents = new ExecuteEvents(this); 
    display = (TextView) view.findViewById(R.id.display); 
    powermenu = (Button) view.findViewById(R.id.powermenu); 
    turnoffscreen = (Button) view.findViewById(R.id.turnscreenoff); 
    mapButton = (ImageButton) view.findViewById(R.id.mapButton); 
    SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS); 
    if(SP.contains(PBConstants.INPUT_DEVICE_TAG)) 
     display.setText(getResources().getString(R.string.configured)); 
    mapButton.setOnClickListener(this); 
    powermenu.setOnClickListener(this); 
    turnoffscreen.setOnClickListener(this); 

    Dialog dialog = new Dialog(this); 
    dialog.setContentView(view); 
    dialog.setTitle(getResources().getString(R.string.app_name)); 
    dialog.show(); 
} 

それは80kbに減少:私はまた、アプリケーションのサイズで別の奇妙な変化に気づい

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    dialog = new Dialog(this); 
    dialog.setContentView(R.layout.main_layout); 
    executeEvents = new ExecuteEvents(this); 
    display = (TextView) dialog.findViewById(R.id.display); 
    powermenu = (Button) dialog.findViewById(R.id.powermenu); 
    turnoffscreen = (Button) dialog.findViewById(R.id.turnscreenoff); 
    mapButton = (ImageButton) dialog.findViewById(R.id.mapButton); 
    SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS); 
    if(SP.contains(PBConstants.INPUT_DEVICE_TAG)) 
     display.setText(getString(R.string.configured)); 
    mapButton.setOnClickListener(this); 
    powermenu.setOnClickListener(this); 
    turnoffscreen.setOnClickListener(this); 
    dialog.setTitle(getString(R.string.app_name)); 
    dialog.show(); 
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 
     @Override 
     public void onDismiss(DialogInterface dialogInterface) { 
      dialog.dismiss(); 
      MainActivity.this.finish(); 
     } 
    }); 
} 

を、私は、コードの最後のスタイルでアニメーションを追加しようとしたとき(80kb 1) 。アプリのサイズはひどく1 MBになりました。これは私がアニメーションを初期化し、ボタンがクリックされたときにそれを呼び出してみました方法です:

private static final ScaleAnimation animation = new ScaleAnimation(1, .95f, 1, .95f, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);//declared as global variable 

のonCreateメソッド内:私はonClickListenerでそれを呼ば

animation.setDuration(1000); 
animation.setFillAfter(false); 

た後:

mapButton.startAnimation(animation); 

新しいリソースを追加せずにコードのスタイルのみを変更した場合、アプリケーションサイズが大幅に変化するのはなぜですか?ダイアログの中にあるウィジェットを初期化する方法には、このような大きな違いがどこにありますか?私が追加した方法でアニメーションを追加すると、なぜ大きな違いがありますか?

は質問をフォローアップ:

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.main_layout); 
    executeEvents = new ExecuteEvents(this); 
    display = (TextView) this.findViewById(R.id.display); 
    powermenu = (Button) this.findViewById(R.id.powermenu); 
    turnoffscreen = (Button) this.findViewById(R.id.turnscreenoff); 
    mapButton = (ImageButton) this.findViewById(R.id.mapButton); 
    SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS); 
    if(SP.contains(PBConstants.INPUT_DEVICE_TAG)) 
     display.setText(getResources().getString(R.string.configured)); 
    mapButton.setOnClickListener(this); 
    powermenu.setOnClickListener(this); 
    turnoffscreen.setOnClickListener(this); 
} 

投機

が、これは輸入されているパッケージまたはクラスが原因だろうか?質問のanimationビットは少なくとも意味があります。

ビューが初期化されるコンテキストを追加すると、メモリ使用量が減少しますか?

+0

APKを解凍し、コンポーネントを分析することができます。 dexファイル(http://code.google.com/p/smali)を解析してその構造を見ることもできます。 –

+0

APKのサイズは同じです。インストールサイズが異なります。 –

+0

うわー、それは面白いです。ルートデバイス上では、インストールされたアプリケーションに関連する個々のファイルを分析することができます。 'ls -l/data/app/{package}'、 'ls -l/data/data/{package}'と同様です。 –

答えて

9

すべてのあなたのJavaコードを最初に言うjavacによってJavaバイトコードにコンパイルされて知っているかもしれないようにうん、あなたの推測が正しいと接近している、そしてdxは、のDalvikバイトコード、あなたのDalvikバイトコードファイル(別名dex)に変換されますapk内にパッケージ化されています(btw apkのサイズはzip圧縮に役立ちます)。通常はclasses.dexとなります。後でapkをデバイスにインストールすると、Androidはその特定のデバイス(別名odex)に最適化します。

最終的にキャッシングされたdexが実際に変更されていることを確認するには、アニメーションを追加するだけで、このサイズ変更が発生します。apkを解凍するか、デバイス内で見つけることができます。エキサイティング:だからここ

は(あなたの80kb)アニメーションなしであなたのdexです:

http://i.imgur.com/2JkpWS3.png

、アプリ情報:

http://i.imgur.com/HseGJih.png

だからここにアニメーション(あなた1 MB)を使用してdexです:あなたは、彼らが本当にある見つけることができる

http://i.imgur.com/FSVPWAC.png

詳しく見:

http://i.imgur.com/pyrthYd.png

、アプリ情報あなたのdalvikバイトコードの定数プールでちょうど見ることで違う:

http://i.imgur.com/02mqaif.png

私は、このようなラジカルのサイズ差を取得していない、まだそれがnoticiableあるいくつかの理由について、私はので、私は、彼らが助けを考えると、物事を少し最適化のGradle + Androidのメーカーを使ってアプリを構築しました。

最後に、ProGuardを使用することもできますが、ちょっとね!いくつかのkは今日はそれほどではありませんが、私はあなたのアプリに「脂肪」を追加することを心配することはありません。もちろん、改善の余地はありますが、java4kやstuffそのように:)

+0

これらの変更を実行したとき、アプリケーションのパフォーマンスは実装スタイルによって異なりますか? –

+0

@Torcelliteもう一つの質問ですが、パフォーマンスについて心配する前に、 'MainActivity'をすべて' static'メンバーと一緒に漏らすことについてまず心配する必要があると思います。 – eveliotc

+0

静的メンバーにはインスタンスが1つしかないので、漏れの原因になりません。私の無知を赦してください。私は学ぶことを試みている。 –

関連する問題