Issue related to using Android attribute (attr) defined in other aar package -


मान लें कि attr को aar पैकेज में परिभाषित किया गया है ( Com.pack1 ) के रूप में

  & lt; attr name = "attr0" format = "string" / & gt;  

और दूसरे पैकेज में ( com.pack2 पर com.pack1 पर निर्भरता है, कहें)) मैं एक styleable < / कोड> के रूप में

  & lt; attr name = "attr2" format = "integer" / & gt; & Lt; घोषित-शैली योग्य नाम = "दृश्य 2" & gt; & Lt; attr name = "attr1" format = "string" / & gt; & Lt; attr name = "attr2" / & gt; & Lt; / घोषित-Styleable & gt;  

और मेरे पास com.pack2 के रूप में एक कस्टम दृश्य है

  सार्वजनिक वर्ग View2 LinearLayout {सार्वजनिक View2 (संदर्भ संदर्भ , AttributeSet attributeSet) {सुपर (संदर्भ, विशेषता सेट); View.inflate (संदर्भ, R.layout.view2, यह); कोशिश करें {टाइप किए गएअरे टाइप कियाअरेरे = संदर्भ। शौकीन स्टाइल गुण (विशेषतासैट, आर। स्टेलेबल.विवरण 2); {If (typedArray.hasValue (R.styleable.view2_attr1)) {String t = typedArray.getString (R.styleable.view2_attr1); Logger.debug ("attr1 - & gt; मूल्य है - & gt; {}", टी); } Else logger.debug ("attr1 - & gt; कोई मान नहीं"); यदि (टाइप कियाअरेरेएचएएसएवल्यू (आर.स्टेबल। वीवी 2_टाट्र 2)) {int t = typedArray.getInteger (R.styleable.view2_attr2, 0); Logger.debug ("attr2 - & gt; मूल्य है - & gt; {}", t); } Else logger.debug ("attr2 - & gt; कोई भी मान नहीं"); } TypedArray.recycle (); } कैच (थ्रोहेबल टी) {लॉगर। डीबग (टी.ओस्टस्ट्रिंग ()); }}}  

और मैं एक कस्टम लेआउट को

  & lt; LinearLayout xmlns के रूप में जोड़ता हूं: एंड्रॉइड = "http://schemas.android Com / apk / res / android "xmlns: custom =" http://schemas.android.com/apk/res-auto "एंड्रॉइड: अभिविन्यास =" लंबवत "एंड्रॉइड: layout_width =" fill_parent "एंड्रॉइड: layout_height =" fill_parent " & gt; & Lt; com.pack2.View2 android: layout_width = "fill_parent" एंड्रॉइड: layout_height = "wrap_content" कस्टम: attr1 = "यह एक परीक्षा है" कस्टम: attr2 = "1000" / & gt; & Lt; / LinearLayout & gt;  

यहां तक ​​कि जब मैं ऐप चलाता हूं तो सबकुछ ठीक होता है और लॉगगर की रिपोर्ट है कि

  attr1 - & gt; मूल्य है - & gt; यह एक परीक्षण एट्रेट 2 - & gt; मूल्य है - & gt; 1000  

लेकिन जैसे ही मैं styleable जैसा

  & lt; attr name = "attr2" format = "integer बदलता हूं "/ & Gt; & Lt; घोषित-शैली योग्य नाम = "दृश्य 2" & gt; & Lt; attr name = "attr0" / & gt; & Lt; attr name = "attr1" format = "string" / & gt; & Lt; attr name = "attr2" / & gt; & Lt; / घोषित-Styleable & gt;  

और एप को चलाने के लिए मुझे गलत परिणाम मिलते हैं I लॉगगर की रिपोर्ट है कि

  attr1 - & gt; कोई मान  

और कोई अपवाद हुआ

  java.lang.UnsupportedOperationException: पूर्णांक में कनवर्ट नहीं किया जा सकता: प्रकार = 0x3  

यह मान की तरह लग रहा है "यह एक परीक्षा है" attr0 के लिए उपयोग किया जाता है, हालांकि उस विशेषता को लेआउट में परिभाषित नहीं किया गया है। ध्यान दें कि ऐप ठीक से संकलित हो जाता है, लेकिन परिणाम गलत है।

मुझे ऐसा क्यों मिलता है?


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -