2016-01-05 5 views
18

मैं एंड्रॉइड स्टूडियो 1.5.1org.apache.poi और javax.xml.stream को एकीकृत करना। * एंड्रॉइड में पैकेज (stax-api) - एंड्रॉइड स्टूडियो में --कोर-लाइब्रेरी तर्क कैसे सेट करें?

का उपयोग कर रहा हूं, मैं अपने एंड्रॉइड प्रोजेक्ट में org.apache.poi-ooxml लाइब्रेरी को शामिल करना चाहता हूं। उस पुस्तकालय को शामिल करने के लिए मुझे कुछ अन्य लाइब्रेरी निर्भरताओं को शामिल करने की आवश्यकता थी, जिनमें से स्टैक्स-एपीआई लाइब्रेरी शामिल थी।

स्टैक्स एपीआई के साथ समस्या यह है कि इसमें जैवक्स में सभी पैकेज हैं। * जो "कोर लाइब्रेरी" है। जावा जेडीके में इन सभी पुस्तकालयों को शामिल किया गया है, इसलिए यदि मैं इसे जावा एसई में उपयोग करना चाहता था, तो मुझे उस स्टैक्स-एपीआई लाइब्रेरी की आवश्यकता नहीं होगी। दूसरी ओर, एंड्रॉइड में "आंशिक" स्टैक्स-एपीआई लाइब्रेरी है। एंड्रॉइड के लिए मुझे केवल javax.xml.stream की आवश्यकता है। * पैकेज। इसका मतलब है कि मुझे stax-api निकालने की जरूरत है, javax.xml.stram पैकेज को छोड़कर सब कुछ हटा दें, और इसे दोबारा दोबारा दोबारा हटा दें।

तो मुझे लगता है कि एंड्रॉइड में इस संशोधित लाइब्रेरी का उपयोग करना सुरक्षित है। लेकिन, यह javax पैकेज है, जो एंड्रॉयड स्टूडियो के अनुसार एक कोर पुस्तकालय है, इसलिए एंड्रॉयड स्टूडियो (या जो भी एंड्रॉयड स्टूडियो में घटक) मुझे एक चेतावनी देता है *:।

trouble processing "javax/xml/stream/EventFilter.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.

This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on.

However, you might actually be trying to define a class in a core namespace, the source of which you may have taken, for example, from a non-Android virtual machine project. This will most assuredly not work. At a minimum, it jeopardizes the compatibility of your app with future versions of the platform. It is also often of questionable legality.

If you really intend to build a core library -- which is only appropriate as part of creating a full virtual machine distribution, as opposed to compiling an application -- then use the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact building an application, then be forewarned that your application will still fail to build or run, at some point. Please be prepared for angry customers who find, for example, that your application ceases to function once they upgrade their operating system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a core package, then the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace. This means that they will never be in conflict with core system classes. JarJar is a tool that may help you in this endeavor. If you find that you cannot do this, then that is an indication that the path you are on will ultimately lead to pain, suffering, grief, and lamentation.

तो, मैं चाहता हूँ इस --कोर पुस्तकालय विकल्प का उपयोग करने के लिए। लेकिन इसे कहाँ सेट करें?

मैंने पहले से ही Android Studio ignore --core-library flag देखा जो मेरी मदद नहीं करता था। मुझे लगता है कि उन उत्तरों को पुराना है, और यही कारण है कि मैं एक नया सवाल पूछ रहा हूं।

क्या मैं कोशिश किया:

  1. build.gradle:

    dexOptions { 
        coreLibrary true; 
    } 
    
  2. build.gradle:

    dexOptions { 
        preDexLibraries = false 
    } 
    
    project.tasks.withType(com.android.build.gradle.tasks.Dex) { 
        additionalParameters=['--core-library'] 
    } 
    
  3. फ़ाइल -> अन्य सेटिंग्स - > डिफ़ॉल्ट सेटिंग्स -> कंपाइलर -> एंड्रॉइड कंपाइलर और जाँच इन काम के '--core-पुस्तकालय झंडा जोड़ें'

कोई नहीं। क्या उस विकल्प को सेट करने का कोई तरीका है?


संपादित करें: मैं क्यों STAX की आवश्यकता है: मैं वर्कबुक, शीट, कॉलम, .xlsx फ़ाइलों के लिए कोशिकाओं के साथ कुछ सामान कर रहा हूँ। जब मैं केवल poi-ooxml-3.14-beta1-20151223.jar शामिल करता हूं मुझे class file for org.apache.poi.ss.usermodel.Workbook not found कहने के निर्माण समय में त्रुटि मिलती है।

क्रम पर poi-3.14-beta1-20151223.jar सहित मैं दूसरों के बीच में मिलता है,, Could not find method org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.isSetBookViews, referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook पर

Failed resolving Lorg/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook; interface 59 'Lorg/apache/xmlbeans/XmlObject; और java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook

रनटाइम के दौरान poi-ooxml-schemas-3.14-beta1-20151223.jar सहित मैं दूसरों के बीच में मिलता है,, Could not find method javax.xml.stream.events.Namespace.getPrefix, referenced from method org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.getQName और java.lang.NoClassDefFoundError: javax.xml.stream.XMLEventFactory at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)

अद्यतन तो रनटाइम के दौरान xmlbeans-2.6.0.jar सहित मैं दूसरों के बीच में मिलता है,, पर पर

, http://poi.apache.org/faq.html#faq-N1017E

से

18. Why do I get a java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventFactory.newFactory()

This error indicates that the class XMLEventFactory does not provide functionality which POI is depending upon. There can be a number of different reasons for this:

Outdated xml-apis.jar, stax-apis.jar or xercesImpl.jar:

  • These libraries were required with Java 5 and lower, but are not actually required with spec-compliant Java 6 implementations, so try removing those libraries from your classpath. If this is not possible, try upgrading to a newer version of those jar files.
  • Running IBM Java 6 (potentially as part of WebSphere Application Server): IBM Java 6 does not provide all the interfaces required by the XML standards, only IBM Java 7 seems to provide the correct interfaces, so try upgrading your JDK.
  • Sun/Oracle Java 6 with outdated patchlevel: Some of the interfaces were only included/fixed in some of the patchlevels for Java 6. Try running with the latest available patchlevel or even better use Java 7/8 where this functionality should be available in all cases.

तो, अगर मैं आर एंड्रॉइड में यह सही ढंग से खाएं, मुझे "छोटा" STAX api की आवश्यकता है।

+0

अपाचे पीओआई के नवीनतम संस्करणों द्वारा एसटीएक्स की आवश्यकता नहीं है। यदि आप उन्नयन करने का प्रयास करते हैं तो क्या होता है? – Gagravarr

+0

मैंने एसओएक्स – SlumpA

+0

के उपयोग को "न्यायसंगत" करने के लिए प्रश्न को अद्यतन किया है [पीओआई के किनारे पर निर्भरता के विवरण के लिए [अपाचे पीओआई घटक पृष्ठ] (http://poi.apache.org/overview.html#components) देखें। सलाह के बाद आपके लापता वर्ग के मुद्दों को ठीक कर देगा – Gagravarr

उत्तर

3

अपाचे पीओआई और यह एंड्रॉइड एप्लिकेशन में निर्भर पुस्तकालयों का उपयोग करने की कोशिश करते समय कई समस्याएं हैं। दूसरों के अलावा xmlbeans.jar में डुप्लिकेट कक्षाएं हैं, "javax। *" पैकेज एंड्रॉइड कंपाइलर और कुछ अन्य लोगों द्वारा निषिद्ध हैं।

वर्तमान में दो परियोजनाएं हैं जो उन समस्याओं को ठीक करने की कोशिश कर रहे हैं:

android5xlsx रेडीमेड जार-फाइलों में शामिल करने के लिए प्रदान करता है अपने आवेदन, लेकिन वर्तमान में पीओआई के कुछ पुराने संस्करण का उपयोग करता है। Poi-on-android पीओआई 3.15-बीटा 1 पर आधारित है और पीओआई के नए संस्करणों के लिए काफी आसानी से पुन: संकलित किया जा सकता है। दोनों परियोजनाएं एंड्रॉइड 5+ के लिए हैं और नमूना कोड के साथ आती हैं और एंड्रॉइड पर अपाचे पीओआई के मूल उपयोग की अनुमति देनी चाहिए।

+0

आपके कड़ी मेहनत के लिए धन्यवाद! क्या मैं आपसे दो प्रश्न पूछ सकता हूं?सबसे पहले, ऐसी अधिकांश परियोजनाएं केवल एंड्रॉइड 5+ का समर्थन क्यों करती हैं? एक ही समय में कम संस्करणों का समर्थन करने के लिए कोई समस्या है? दूसरा, अगर मुझे एंड्रॉइड 4.4 और ऊपर के लिए लिखने की ज़रूरत है, तो कौन सा प्रोजेक्ट मेरे लिए सबसे अच्छा होगा? मैंने देखा कि आपने कुछ अन्य उत्तरों में एंड्रॉइड रीडएक्सएलएक्स का भी उल्लेख किया है। (ऐप को एक्सएलएस और एक्सएलएसएक्स दोनों को पढ़ने की जरूरत है!) – Jenix

+0

ओह, मैं भी इस सवाल से पूछना भूल गया। क्या आपने उन परियोजनाओं का उपयोग कर किसी भी स्मृति समस्या का अनुभव किया है? मुझे एंड्रॉइड पर एक्सेल फाइलों के साथ कोई अनुभव नहीं है, इसलिए कम अंत उपकरणों के बारे में कुछ हद तक चिंतित है। – Jenix

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

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