Project Not working after updating to API 23 - java

Can anyone please help me with this? I dont know what does this mean.
To give you a back up I updated my sdk with 23 and then i got 101 errors regarding HTTPClient not being resolved. So i followed this link to remove that then I have this error of which i have no clue where to start with.
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\build-tools\23.0.1\dx.bat --dex --no-optimize --output F:\sagarDevanga\workspace\AndNrby\app\build\intermediates\dex\debug --input-list=F:\sagarDevanga\workspace\AndNrby\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/http/ConnectionClosedException;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)

Make sure that your adt supports the version of api that you are running. See this link : https://developer.android.com/tools/support-library/index.html

To fix you should check in libs (.jar) and in your build.gradle if there are some libraries duplicated. This error happen tipicaly when you add a copy of the same library or a library that include a copy of another library that you have already added
Update also your support libs from SDK

Ok I have updated the question's title also so that other people also find it useful.So I will write a detailed answer about how this error occured in my project and the fixes I did and how I finally derived the answer.
1) I updated the SDK and then started to compile my project using the latest api i.e API 23. You can do that by going to File -> Project Structure ->Select your module.
Now in the right hand side window under properties the top two properties can be changed using in the drop down.
Then click on Apply and Ok.
2) So when you do this your app's build.gradle file will look like this. And now everything looks good. It will compile also. But when you run the project you will get a lot of errors by this name Error:(17, 35) error: package org.apache.http.impl.client does not exist Obviously if you are using them in your async tasks.
3) So when i got this error I did a lot of research here and there and then came across this link and added the HTTP CLIENTS jar files in the libs folder and then tried to run the program I ended up with this problem (problem mentioned in the question).
4) So after diggin around I found that the problem was HTTP methods which i used in the Async task were deprecated in the API 23 hence I landed myself in this mess.
5) Then what I did next fixed the problem for me. Refernce given here.
6) In your module's build.gradle file add this line useLibrary 'org.apache.http.legacy' like below.
7) Wait your still not done. Now go to your main build.gradle file and add this line classpath 'com.android.tools.build:gradle:1.3.1' like this . Now build and compile your project everything runs fine.
8) After all this steps the project works fine but I have a doubt in the last pic that i shared which is of the top level build.gradle file. Whether I should keep both the classpaths or just use this classpath 'com.android.tools.build:gradle:1.3.1' and remove the other one. If any one have any idea on this please help.
9) The problem was that they deprecated the HTTP Clients in the Latest Android API 23. Insted of HTTP Client you have to use HttpUrlConnection but if you want to continue using HTTP client for NOW follow the steps above.

Related

failed parsing overlays - Aapt2 - Android Studio

I'm trying to use dlib in Android Studio for my university's project.
I did import all the .so files that I needed, but I can't import the shape_predictor_68_face_landmarks.dat... (I want to import it as a raw file)
I get AAPT2 error: check logs for details and the Java compiler says failed parsing overlays. Do you know what can I do to fix this ? I've never seen a topic about failed parsing overlays.
I already tried to put android.enableAapt2=false in the gradle.properties and the testOptions in the gradle.build without success...
You can find the build log here : Build log
And the project here : https://github.com/ghysc/Stage
If you need any more information, please let me know.
Thanks for reading.
Cyril G
Using your GitHub project I found out it was a problem with one of the resource files you had - it was too big for AAPT2 to process:
./app/src/main/res/raw/shape_predictor_68_face_landmarks.dat
This was a bug in AAPT2 but it has been fixed recently.
So if you update your android gradle plugin version in your build.gradle file to 3.2.0-alpha11 or newer it all compiles fine:
classpath 'com.android.tools.build:gradle:3.2.0-alpha11'
Huh, actually I just solved this problem in another way.
When I imported the project of tzutalin ( : github.com/tzutalin/dlib-android-app), I changed the name of the package, which is why my program couldn't find where the library where stored !
I re-named the package package com.tzutalin.dlib; for the dlib library and everything is fine now.

Using jackson-dataformat-xml on android

I'm strugling with using jackson-dataformat-xml on android
I have some very basic code that works fine on oracle jre
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
First I tried official documentation adapted for gradle (by me, not sure if done correctly):
compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'javax.xml.stream:stax-api:1.0-2'
Result: gradle fails build time about bundling corelibraries into an application
...
:app:preDexDebug
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.
...
2nd attempt trying to follow Sean's answer
(Basicly he repackages corelibs with prefix names and rebuilds jackson-dataformat-xml to use the prefixed names)
compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'
// Repackaged XML-specific libraries
compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'
compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'
compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'
compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'
And build time failed on duplicates
Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec
so added:
packagingOptions {
...
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
When adding the exclusions it builds and deploys, but fails runtime on below stackdump (AFAIK it cant find the SAX provider, even tho it is added to the classpath to my understanding)
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:97)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:82)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:46)
What is the proper way to move forward on either #1 or #2?
Number 2 is the correct approach (Android doesn't like it when you include classes in the official Java package namespace - but then again, I wrote the original answer so I'm biased ;) ).
I believe the FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found error is due to a bug in the Android build tools. In previous versions of ADT for Eclipse and Gradle plugin < 0.7.0 the /META-INF/* files are stripped from the JARs during the build process. It seems like >= v0.7.0 shouldn't have the problem according to Google, but from others' reports it sounds like it still may be problematic, and could potentially remove the META-INF/services/javax.xml.stream.XMLInputFactory file, which is required for the platform to register Aalto.
Try the workaround mentioned in AOSP issue 59658 comment 22:
right click on /src/main (where you have /java and /res folders),
select New > Folder > Java Resources Folder,
click Finish (do not change Folder Location),
right click on new /resources folder,
select New > Directory
enter "META-INF" (without quotes),
right click on /resources/META-INF folder,
select New > Directory
enter "services" (without quotes)
copy any file you need into /resources/META-INF/services
For you, in step 10 above you'd need to copy this file into /resources/META-INF/services. In case the file link is broken in the future, the name of the file is javax.xml.stream.XMLInputFactory and it consists of a single line:
com.fasterxml.aalto.stax.InputFactoryImpl
EDIT
If you get a "Error:duplicate files during packaging of APK... Path in archive: META-INF/services/javax.xml.stream.XMLInputFactory", you can try telling Gradle to keep the first occurrence with:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.xml.stream.XMLInputFactory'
}
}
EDIT 2
This bug may be affecting "pickFirst". Please make sure you're running the latest version of Android Studio, and update your local tools and Android Gradle plugin to make sure you're running the most recent version of the tools. This may be fixed in Android Studio 1.3 RC1.
I have attempted to add XmlPull support to jackson xml. Find the forked project here:
https://github.com/finvu/jackson-dataformat-xml
Currently, only supported for version 2.9.6. (clone the branch jackson-dataformat-xml-2.9.6-XmlPull)
Sorry, I am not able to provide detailed documentation due to time constraints. If you have knowledge of git and maven to pull a specific branch and build the jar, then it should be relatively easy.
To those who will be in need of this in the future:
first integrate Jitpack in Your Android app, following their instructions:
https://jitpack.io/
Then paste teh GitHub url of jackson-dataformat-xml on Jitpack sites' corresponding text box. GitHub url is:
https://github.com/FasterXML/jackson-dataformat-xml.
That's it! Enjoy the result. :)

Android Studio - Resource Entry already defined

After compiling my Android application using the Android Studio (Beta), I have the following error:
Error:error: Resource entry background is already defined.
res\drawable-xhdpi-v4\background.9.png:0: Originally defined here.
This occurred when I had a image file called "background" in my res folder.
I then made a 9 patch version of it and pasted it in the same folder. This meant that there was 2 files with the same name. So I unsurprisingly I had this error.
However I now deleted all instances of the background image file (including the 9 patch version and original image) in my code and layout file and I still have this error.
You could try to do one of the following:
Clean and Build or gradle clean build assemble
Invalidate and restart Android Studio
1 Build > Clean Project
2 Build > Rebuild Project
I am using Android studio and I run exactly into the same issue and none of the answers I found on the web helped me solve the problem, including the previous one. So reading through all details of the error messages and found this lines:
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\user\AppData\Local\Android\android-studio\sdk\build-tools\android-4.4W\aapt.exe package -f --no-crunch -I C:\Users\user\AppData\Local\Android\android-studio\sdk\platforms\android-20\android.jar -M C:\Users\user\AndroidStudioProjects\DartsApp\app\build\intermediates\manifests\debug\AndroidManifest.xml -S C:\Users\user\AndroidStudioProjects\DartsApp\app\build\intermediates\res\debug -A C:\Users\user\AndroidStudioProjects\DartsApp\app\build\intermediates\assets\debug -m -J C:\Users\user\AndroidStudioProjects\DartsApp\app\build\generated\source\r\debug -F C:\Users\user\AndroidStudioProjects\DartsApp\app\build\intermediates\libs\app-debug.ap_ --debug-mode --custom-package com.dartstransit.dartsapp -0 apk --output-text-symbols C:\Users\user\AndroidStudioProjects\DartsApp\app\build\intermediates\symbols\debug
Error Code:
1
Output:
res\drawable-hdpi-v4\bus_w.png:0: error: Resource entry bus_w is already defined.
res\drawable-hdpi-v4\bus_w.jpg:0: Originally defined here.
As you can see there are two files of name bus_w with different extensions on the same folder. I had already removed those files from the project and still getting the error, so I decided to check every single folder of the project that was reference in the compiler line in the error message. Finally found that there was a copy of the file bus_w.png in the folder app\build\intermediates\res\debug\drawable-mdpi-v4.
I just deleted it and voila, problem solved.
A simple Build > Rebuild project helped me
Did you try rename this file to other name? It seem one of your libraries have same resource.
I see that many devs(include me) had issue with ic_launcher too. I think you want to try mipmap instead drawable. So we will have something like this:
\res\mipmap-hdpi
\res\mipmap-mdpi
\res\mipmap-xhdpi
\res\mipmap-xxhdpi
Hope this help.
I have also encountered this error recently.Here is my solution that works,hope it will help you.
1.only keep 9 patch version image in the drawable-hdpi folder
2.make sure the code related to this problem in xml file remains the same: android:background="#drawable/msg_left"
instead of using the code:
android:background="#drawable/msg_left.9"
PS:My original image name is msg_left,and my 9 patch version image name is msg_left.9
I did the trick by moving the icon
drawable/ic_launcher
to
mipmap/ic_launcher
and it worked fine :)
In my case the problem was that I had more than one '.' in the filename. like:
a.png
a.bold.png
Solution was to rename to
a.png
a_bold.png
In our case, problem started occurring (error shows 'duplicate value for resource' in a library) when some other library was upgraded to it's latest version.
We just downgraded the version of the library that was upgraded.
Real pain was because that we have many dependencies which can be dynamically upgraded when there is a new version available in repositories. So my teammate had to go through all libs that can be dynamically upgraded and see if there is one that is recently upgraded, try to downgrade it and check if build goes fine. He identified many were upgraded on previous day. Downgrading one of them got the build back.
Conclusion we made is not to use Dynamic Versioning. Don't use dynamic versions for your dependencies.
This was the error by the way:
Task :app:generateDebugResources UP-TO-DATE
AGPBI: {"kind":"error","text":"error: duplicate value for resource \u0027attr/itemBackground\u0027 with config \u0027\u0027.","sources":[{"file":"/Users/unknownuser/.gradle/caches/transforms-1/files-1.1/singledateandtimepicker-1.2.2.aar/86ae3786d70c769e610c8a01d58aa638/res/values/values.xml","position":{"startLine":15,"startColumn":4,"startOffset":2427,"endColumn":48,"endOffset":2471}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource previously defined here.","sources":[{"file":"/Users/unknownuser/.gradle/caches/transforms-1/files-1.1/singledateandtimepicker-1.2.2.aar/86ae3786d70c769e610c8a01d58aa638/res/values/values.xml","position":{"startLine":15,"startColumn":4,"startOffset":2427,"endColumn":48,"endOffset":2471}}],"original":"","tool":"AAPT"}
Task :app:mergeDebugResources FAILED
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
FAILURE: Build failed with an exception.

Could not find property 'allJava' on source set main

Hy, I am using Android Studio 0.6.0 as of this morning, during the upgrade process I had to switch to Gradle version 0.11 to compile my Android project.
Ever since I get this annoying error which prevents me from building my project.
Error:Could not find property 'allJava' on source set main.
This property is defined only for the 'java' plugin, but I am using the 'android' plugin in my build.gradle file, so I see no reason why I should receive this error.
Does anyone know how to get rid of this message?
UPDATE:
I solved it, it seems this property is no longer available in Gradle 0.11.1, and somebody somewhere in my project was using it.
I found this line in one of the build.gradle files:
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
which made a reference to another gradle configuration file, that used this property to make a task of generating JavaDocs for every .java file.
So in order to solve this problem, just look everywhere in your code for a reference to this property.
In case anyone happens upon this thread, I did a little investigating into the Gradle Android plugin source.
It appears that the allJava property was removed as it was redundant with the java property. Swapping allJava out for 'java' seems to fix the issue.
https://android.googlesource.com/platform/tools/base/+/5e71a83f74258b85d7f5306bf743c4d69d6242f8%5E%21/#F2
Consequently, the allSource property was also removed, which will break the gradle-mvn-push script as well. I have submitted a bug report for that one, linked below.
https://code.google.com/p/android/issues/detail?id=71174

Didn't find class on path: dexpathlist

Seriously, i don't know what to do to solve this problem.
My android project was working fine, until i needed to import a library with Maven. Since that, everything started to collapse.
What is happening: When i start my application, the following error appears on LogCat and android tells that my app stopped working. I've searched for this similar error here AND on the rest of the internet, but everything people did haven't worked for me.
Error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.buscaserra/com.buscaserra.main.ActivitySplash}: java.lang.ClassNotFoundException: Didn't find class "com.buscaserra.main.ActivitySplash" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.buscaserra-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.buscaserra-2, /vendor/lib, /system/lib]]
Manifest and packages:
Build Path:
Same problem here.
What worked for me was adding android-support-v4.jar as a lib and making sure it was checked on Project properties -> Build Path -> Order & export.
It was mentioned here
I had the same problem when I moved the project folder from a Linux machine to a Mac.
What I did was:
Close the project
Remove the .iml file
Import the project using the "Create new project using existing code"
I am using IntelliJ.
Cheers.
I did the following steps to resolve the issue on Android Studio.
open file ./app/build.gradle
reduce compileSdkVersion (e.g. 22 -> 21)
click 'sync project with gradle file'
change back to the original compileSdkVersion (e.g. 22)
click 'sync project with gradle file'
recompile and it should work.
I have spent way to many hours on this stupid issue but finally got it resolved:
When creating a new project -> package name is causing this stupid dex issue to appear, must not be able to find the main activity during run time with whatever deployment assemply setup. Android Studio doesn't like some of my commonly used package names, I'm completely baffled..I think this is a pretty big bug haha
Given the following new project parameters:
Name: NotificationApp,
packageName: com.stores.business.notificationapp,
saveLocation: /home/me/AndroidStudioProjects/NotificationApp
I would get the following error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.stores.business.notificationapp/com.stores.business.notificationapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.stores.business.notificationapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.stores.business.notificationapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.cvs.stores.myapplication-2/lib/arm64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
My Solution
I resolved it by changing the package name to:com.notificationapp, then File->invalidate caches/Restart..hope this helps someone else haha
Do you have any required projects on the build path? Can't tell from your screen shot but check your "Projects" tab. You may have inadvertently added a Project Library as a required project instead. Remove the project from the Projects tab and then project -> properties. Click Android, add the project as a library instead here...
Make sure that any compatibility lib jars that you're using in your main project (like android-support-v4.jar) are the same versions as those used in any of the projects that your main project references.
I had this same problem and what solved it was to copy and paste the android-support-v4.jar from another library project (that my main project was referencing) and pasting it into my main project's /libs folder.
I had the same issue.
Nothing had changed except Android studio and Gradle updated since I last compiled.
I took a look at the build options under Build>Edit Build Types and noticed that the one option that was different between my project that didn't run and the ones that did work was the Minify Enable option.
I set it to false and now everything works again.
I should understand the problem by just seeing "dex errors".But it took half day to fix the issue.
I fix this by following android developers page's instruction: https://developer.android.com/studio/build/multidex.html
First add this to my gradle.build:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Then I extend my Application class (or declare the application class in AndroidManifest.xml or override attachBaseContext() function) as instructed by the MultiDexApplication class document on the page. This have fixed my problem.

Categories

Resources