2013-07-12 12 views
11

मैंने हाल ही में रूट उपयोगकर्ताओं के लिए यह application बनाया है जो अक्सर उनके डिवाइस को संशोधित करते हैं।एप्लिकेशन इंस्टॉल आकार फोन पर कैसे भिन्न होता है?

अब मैंने एप्लिकेशन के इंस्टॉल आकार के साथ बहुत अजीब व्यवहार देखा है।

जब मैंने एक्सएमएल फ़ाइल से शुरू किए गए विचारों के साथ एक नियमित गतिविधि का उपयोग किया, तो आकार 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 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 विधि के अंदर::

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

जो बाद मैं यह onClickListener में कहा जाता है:

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

आप अपने एपीके को अनजिप कर सकते हैं और इसके घटकों का विश्लेषण कर सकते हैं। आप इसकी संरचना देखने के लिए डीएक्स फ़ाइल (http://code.google.com/p/smali) को भी विच्छेदित कर सकते हैं। –

+0

एपीके का आकार समान है। स्थापना का आकार अलग है। –

+0

वाह, यह दिलचस्प है। एक रूट डिवाइस पर आप एक स्थापित अनुप्रयोग से संबंधित व्यक्तिगत फ़ाइलों का विश्लेषण कर सकते हैं, हालांकि। जैसे, 'ls -l/data/app/{package} ',' ls -l/data/data/{package} '। –

उत्तर

9

हाँ, अपने अटकलों सही हो सकता है, तो के रूप में आप कहते हैं javac द्वारा अपने सभी जावा कोड पहले जावा बाईटकोड को संकलित किया गया है पता हो सकता है करीब हैं, तो dx उन्हें Dalvik बाईटकोड को, धर्मान्तरित अपने Dalvik बाईटकोड फ़ाइल (उर्फ dex) है आपके एपीके के अंदर पैक किया गया है (बीटीडब्ल्यू एपीके आकार ज़िप्प संपीड़न में मदद करता है क्योंकि आमतौर पर classes.dex) जो बाद में जब आप अपने डिवाइस में एपीके स्थापित करते हैं, तो एंड्रॉइड उस विशेष डिवाइस (उर्फ odex) के लिए अनुकूलित कर सकता है।

तो सत्यापित करें कि अपने अंतिम कैश्ड dex वास्तव में बदल देता है और इस आकार परिवर्तन के लिए जिम्मेदार है, से कहते हैं कि सिर्फ जोड़ने एनिमेशन, आप इसे या तो आपके apk अनज़िप करने से या अपने डिवाइस के अंदर प्राप्त कर सकते हैं, मैं हमेशा अधिक दूसरा विकल्प लगता है रोमांचक:

तो यहाँ

एनीमेशन के बिना अपने dex (अपने 80kb) है:

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

और अपने अनुप्रयोग की जानकारी:

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

तो यहाँ

एनीमेशन के साथ अपने dex (अपने 1 MB) है:

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

और अपने अनुप्रयोग की जानकारी:

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

करीब से देखने पर आप पा सकते हैं वे वास्तव में कर रहे हैं अपने दाल्विक बाइटकोड स्थिरांक पूल में बस देखकर अलग:

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

किसी कारण मैं ऐसे कट्टरपंथी आकार अंतर फिर भी यह noticiable है नहीं मिला के लिए, मैं तो मैं वे मदद और चीज़ें थोड़ी अनुकूलन लगता Gradle + एंड्रॉयड स्टूडियो उपयोग करके आपके एप्लिकेशन का निर्माण किया।

अंत में, आप ProGuard का उपयोग कर सकते हैं लेकिन हे! कुछ के इस दिन इतना नहीं हैं, मैं आपके ऐप में कुछ "वसा" जोड़ने की चिंता नहीं करता, जब तक यह बेहतर हो जाता है, निश्चित रूप से सुधार के लिए हमेशा जगह होती है याद रखें कि आप जावा 4k या सामान में नहीं हैं उस तरह :)

+0

जब आपने इन परिवर्तनों को निष्पादित किया था तो आवेदन का प्रदर्शन कार्यान्वयन की विभिन्न शैलियों के साथ भिन्न होता है? –

+0

@Torcellite यह एक और सवाल है, मैं कहूंगा कि आपको प्रदर्शन के बारे में चिंता करने से पहले उन सभी 'स्थिर' सदस्यों के साथ 'मुख्य गतिविधि' के साथ पहली बार लीक करने की चिंता करनी चाहिए – eveliotc

+0

मैं इस धारणा के तहत था कि स्थिर सदस्यों को केवल एक उदाहरण की अनुमति है और इस प्रकार डॉन एक रिसाव का कारण नहीं है। कृपया इस विषय पर मेरी अज्ञानता को क्षमा करें। मैं सीखने की कोशिश कर रहा हूँ। –

संबंधित मुद्दे