"already added" exception with ormlite and gradle - android

I'm using android studio 0.2.3 with gradle 0.5 and added the ormlite dependency to the build.gradle file as follows:
compile 'com.j256.ormlite:ormlite-android:4.9'
Gradle downloaded two jar files: ormlite-android.jar and ormlite-core.jar. The problem is, that the jar files contain identically named classes. So I get the following well known exception:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/j256/ormlite/dao/BaseDaoImpl$1;
Some other solution for the same problem with maven exists, suggesting to exclude the ormlite-core.jar. This should work if all classes from ormlite-core.jar are included in ormlite-android.jar - I didn't check this btw. In that case, I don't understand why the ormlite-core is in this ormlite android dependency package... I'm explicitly adding ormlite-android, as you can see in the snippet above.
But how to exclude the ormlite-core.jar in gradle. Everything I found was for gradle 1.6, but android studio uses gradle 0.5 - or is this just the version of the android gradle wrapper?
.:EDIT:.
To make the dependencies clearer, I add my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.google.android.gms:play-services:3.1.+'
compile 'com.j256.ormlite:ormlite-android:4.9'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
Why I think there are same classes in the two ormlite libs? ==> See the screenshot.
Aren't the opened packages identical? Even the source is. The only distinct classes I found were SqliteAndroidDatabaseType and those in the com.j256.ormlite.android package.

The ormlite-android jar you're using is definitely wrong. My guess is that someone built it incorrectly with ormlite-core exported, which is why you're getting the merge conflicts. If you look at the source for ormlite-android, it isn't supposed to have most of those packages/classes included.
I'm not sure how the ormlite-android versioning works, but it looks like 4.46 is the actual latest version (updated 29-Jul-2013), not 4.9 (updated 26-Jan-2011). I'd recommend using 4.46 instead (that's what works for me) with:
'com.j256.ormlite:ormlite-android:4.46'

Thanks to #cproinger for the answer in another related question.
WOW, now it works! I misunderstood the versioning (my fault). But anyway, the newer version (4.46) contains only the android specific classes in the ormlite-android.jar and everything else in the ormlite-core.jar. Great, thanks #cproinger!

Related

Error trying to render MaterialButton from Material Components

I followed the getting started guide here, I don't want to migrate to androidx at this time so I did:
Made sure I have the correct repositories
Added com.android.support:design:28.0.0-rc01 to my dependencies, since the Getting Started tutorial states this is the only thing needed if I don't want to migrate to androidx.
Made sure compileSdkVersion was 28
Switched to Theme.MaterialComponents.Light.NoActionBar
Downloaded Android P SDK and sources (but not any of the rest that's not on the image):
Made sure I am using AppCompactAtivity
Rebuilt the project
And I still get the error:
The following classes could not be found:
- com.google.android.material.button.MaterialButton
What am I missing?
You should not use com.google.android.material package instead use com.android.support.
In your case android.support.design.button.MaterialButton
I had that problem with Android Studio 3.2 release candidates, both using com.android.support and using com.google.android.material.
I upgraded to the 3.3 canary and that specific problem went away although I now have other (unrelated?) problems (runtime failures to inflate, etc).
I can't find any documentation stating required Android Studio versions for layout editor to work.
Make sure that the repositories section includes Google’s Maven repository google(). For example:
allprojects {
repositories {
google()
allprojects {
repositories {
google()
jcenter()
}
}
Add the library to the dependencies section:
implementation 'com.google.android.material:material:1.0.0'
dependencies {
// ...
implementation 'com.google.android.material:material:1.0.0'
// ...
}

Error: Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat

After upgrading to Android Studio 3.1, I started to get following error during build. Project uses multidex and DX is enabled by default as you would notice in the error. I tried to check dependency graph to understand what is going on but so far have no clue. Interestingly this only fails on my machine. I cleaned up everything, including reinstall etc but nothing worked.
Anyone had the same issue and how did you solve it? Or any direction that I can take a look?
AGPBI: {
"kind":"error",
"text":"Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat",
"sources":[{}],
"tool":"D8"
}
This is the task that fails:
transformDexArchiveWithExternalLibsDexMergerForDebug
I checked similar issues and it seems random things fixes their problem, I'm not sure what is the real cause.
For my solution (I do not know it will work for you):
Firstly I followed #Orhan Obut's solution:
Search for duplicate classes in your project
I found that there are more than one class files in different libraries.
Then I put the ignore annotation above my support dependency in my project module's build.gradle (app folder):
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
I realized that ignorance is no solution, because the error did not go away, even after clean-rebuilding and clearing/invalidating cache for the project.
See: Infographic: 11 Most Common Android Errors and How to Fix Them
So I explored more, and found out this link:
Android - Understanding and dominating gradle dependencies
It suggests ways to resolve conflicts. Hence I put this on my gradle just above the declarations of dependencies:
configurations.all {exclude group: 'com.android.support', module: 'support-v4'}
Since then when I search for duplicate classes for this one using #Orhan Obut's solution above, I find only single entry in the result. That meant that there were no duplicates.
Also, it will be better if you migrate to AndroidX with latest SDK and build tools. Make sure you don't have older support dependencies anywhere.
Happy Coding :-)
I have my solution by change this:
implementation 'com.android.support:appcompat-v7:27.0.0'
to
implementation 'com.android.support:appcompat-v7:26.0.0'
it works for me.
I managed to determine the root cause by using the following steps. It may be different use case for each issue, therefore this is the way to determine the root cause.
Go to android studio
Navigate -> Class
Check include non-project classes
Copy paste full class path with package name. android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
You should be able to see where it is used. Most probably you may need to remove it from one of them.
In my case the issue was ViewPagerIndicator library was downloading support library as jar. Removing it solved the issue.
For the easy option just add
configurations.all {exclude group: 'com.android.support', module: 'support-v4'}
before dependencies in build.gradle app module, it should ignore v4 support libraries, and the duplicate error will go away.
Adding the below line in the build.gradle of the app level worked for me
implementation 'com.android.support:support-v4:28.0.0'
As for me this helps to resolve such issues
all support libraries (also included thirdy-part) reduces to specified version
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0-beta01'
}
}
}
}
I also faced the same problem just a while ago. In my case the third party library used the older AccessibilityServiceInfoCompat version v4 22 and i already updated to newer one v4 28 so both support library classes clashed
In y case I've resolved issue by
implementation 'com.android.support:appcompat-v7:26.0.0'
to
implementation 'com.android.support:appcompat-v7:27.1.1'
some third-party library may be use different version of support library. you can use ./gradlew :app:dependencies find out it, and then import the current version of the support library.
I have my solution by change this :
android / build.gradle
buildscript {
ext {
supportLibVersion = "27.0.3"
}
}
to
buildscript {
ext {
supportLibVersion = "26.0.0"
}
}
directory android / app / build.gradle
defaultConfig {
multiDexEnabled true
}

Android Studio 3.0 Canary 1: Gradle Sync Error

I'm getting this error in my Kotlin project:
Here is my app's Gradle files:
I haven't really done anything to the project yet except add Kotlin and Anko dependencies. Not sure what's happening...
This is a well known issue with Anko. It is mentioned here.
You can try to exclude implicit com.google.android:android dependency from Anko's dependencies:
compile("org.jetbrains.anko:anko-appcompat-v7:$anko_version") {
exclude group: 'com.google.android', module: 'android'
}
(Keep in mind as you are using separate Anko libraries - you may need to use exclusion in multiple pleces).
You can also try to update Gradle plugin:
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
Add the dependency inside you app-level app module :
// Anko
compile 'org.jetbrains.anko:anko-sdk15:0.8.2' // sdk19, sdk21, sdk23 are also available
compile 'org.jetbrains.anko:anko-support-v4:0.8.2' // In case you need support-v4 bindings
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.2' // For appcompat-v7 bindings
As In your screenshot I can see that while adding Anko dependencies you didn't mention the Anko version , kindly mention that it should work fine post that.
Add like this too.
flavorDimensions "default"
productFlavors {
debug {
dimension "default"
...
}
release {
dimension "default"
...
}
foss {
dimension "default"
...
}
}
AFAIK, its Google Repository which is missing. As you can see the ide itself is informing you about it.
Failed to resolve: com.google.android:android.2.3.1 which is Google Repository.
If you are connected to internet then simply click on Install Repository and Sync project in the Gradle Sync window. It will download the google repository and sync your project.

Why won't Android Support Libraries work in my project?

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:
Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#18899229.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:
Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+.
Required by:
:ExpenseTracker:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?
I think you're placing these lines in the wrong file.
They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).
Also, the dependencies tag should not be a child of anything else. something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
...
}
EDIT Did you see the comment? :)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
My problem was that after letting Android Studio upgrade the Gradle plugin to the latest version, it had messed up the dependency section of my module's build file. It had concatenated the dependency declaration lines together (except for the lines that were mere comments). Separating the lines (placing each dependency declaration in a single line) fixed the issue.

Android Studio Gradle Configuration with name 'default' not found

I am having problems compiling my app with Android Studio (0.1.5).
The app uses 2 libraries which I have included as follows:
settings.gradle
include ':myapp',':library',':android-ColorPickerPreference'
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':library')
compile project(':android-ColorPickerPreference')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
When compiling I get this message:
Gradle: A problem occurred configuring project ':myapp'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
Could you help me with this message? Thanks!
In my case, after compiling with gradle tasks --info, the log was there :
Evaluating project ':libraries:VolleyLibrary' using empty build
file.
So it failed to find build.gradle file of the library.
Reason is the folder structure.
It was
-libraries
--volley
---VolleyLibrary
It is supposed to be
-libraries
--VolleyLibrary
I forgot to pull all submodules. So my
compile project(':something')
could not be resolved.
Solution
git submodule update --init
compile fileTree(dir: '//you libraries location//', include: ['android-ColorPickerPreference'])
Use above line in your app's gradle file instead of
compile project(':android-ColorPickerPreference')
Hope it helps
The following procedure solved my issue:
Go to your sub-project-module/library-module settings. (press F4 after selecting the module)
Right Click on Add > Android-Gradle.
Add build.gradle to your module.
Add the following script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
add include ':yourModuleName' in your settings.gradle
I've also faced with this error - I forgot to create build.gradle script for library project.
Yet another cause - I was trying to include a module in settings.gradle using
include ':MyModule'
project(':MyModule').projectDir = new File(settingsDir, '../../MyModule')
Only problem was, I had just imported the module from Eclipse an forgot to move the directory outside my application project, i.e. the path '../../MyModule' didn't exist.
My solution is to simply remove a line from the settings.gradle file, which represents a module that doesn't exist:
include ':somesdk'
and also remove the corresponding line from the main project's build.gradle:
compile project(':somesdk')
I had a git submodule problem when getting this error. Try running gradle tasks --info for a more detailed problem description. I first used gradle tasks --debug, which was not nearly as helpful as --info.
Suppose you want to add a library (for example MyLib) to your project, You should follow these steps:
Prepare your library as a gradle Android library if your library's type is Eclipse ADT
For this job it's enough to import it in Android Studio
Copy your library folder, in this case MyLib folder, and paste it in your main project folder. It's a good practice to create a new folder in your main project folder and name it Libraries
Go to Android Studio and open Settings.gradle file, there you should include your library in your main project. For example include ':MyPrj', 'Libraries:MyLib'. Note: Current directory for this include statement is your main project folder. If you paste your project into a folder you must mention it's address relative to the main project directory. In my case I paste MyLib into Libraries folder. This Libraries name is not a keyword and you can choose other names for it
Open your Project Structure page(File->Project Structure...) click on modules then click on your main project go to dependencies tab click on + then choose Module dependency and there is your libraries and you can select them as you want
Hope it help
In my case I was using Gradle files that work under Windows but failed on Linux. The include ':SomeProject' and compile project(':SomeProject') were case sensitive and were not found.
For me folder was missing which was declared under settings.gradle.
Everything looks fine at first blush, but some poking around on here found an answer that could be helpful: https://stackoverflow.com/a/16905808/7944
Even the original answer writer doesn't sound super confident, but it's worth following up on. Also, you didn't say anything about your directory structure and so I'm assuming it's boring default stuff, but can't know for sure.
One other potential cause of this precise error: I found this error was resolved by commenting some unused libraries in build.gradle dependencies section. Make sure these paths and such are all correct.
I'd look real close at your compile project(':android-ColorPickerPreference') entry in the build.gradle - try commenting out the related code and this line in build.gradle and see if that compiles - then go from there resolving the path or library issue.
I had similar issue and found very simple way to add a library to the project.
Create folder "libs" in the root of your project.
Copy JAR file into that folder.
Go back to Android Studio, locate your JAR file and right click it, choose "Add As Library...", it will ask you only to which module you want to add it, well choose "app".
Now in your "app" module you can use classes from that JAR, it will be able to locate and add "import" declarations automatically and compile just okay. The only issue might be is that it adds dependency with absolute path like:
compile files('/home/user/proj/theproj/libs/thelib-1.2.3.jar')
in your "app/build.gradle".
Hope that helps!
I solved this issue by fixing some paths in settings.gradle as shown below:
include ':project-external-module'
project(':project-external-module').projectDir = file('/project/wrong/path')
I was including an external module to my project and had the wrong path for it.
I had this issue when I manually pasted google-play-services_lib into my project. Obviously, play-services didn't have a build.gradle file in it. The solution, I learned, is to put this dependency in my project's build.gradle (instead of hard-copying the play-services directory):
compile 'com.google.android.gms:play-services:4.0.+'
When i import my library manually i had same issue. I tried to add my library with file > import module and it solved my issue.
In my case I received this error when I misspelled the module name of the library (dependency) in build.gradle file.
So remember to check if the name of the module is correct.
build.gradle
dependencies {
compile project(':module-name-of-the-library')
}
I recently encountered this error when I refereneced a project that was initiliazed via a git submodule.
I ended up finding out that the root build.gradle file of the submodule (a java project) did not have the java plugin applied at the root level.
It only had
apply plugin: 'idea'
I added the java plugin:
apply plugin: 'idea'
apply plugin: 'java'
Once I applied the java plugin the 'default not found' message disappeared and the build succeeded.
Also... check if you have the module files inside your project.
For example, I have an app which uses the Volley module. During my studies on Android development, I accidentally removed the files which were inside the "volley" directory..
~/git/Sandbox/android/HelloWorld/volley $ ll
total 8
drwxrwxr-x 2 ivanleon ivanleon 4096 Jun 16 22:26 ./
drwxrwxr-x 6 ivanleon ivanleon 4096 Jun 17 01:51 ../
I just cloned the project (see bellow) and then, I made the Sync of the project at Android Studio (Tools > Android > Sync Project with Gradle Files), and Gradle build finished normally (Gradle Console: bottom right corner of Android Studio) ;).
~/git/Sandbox/android/HelloWorld/volley $ git clone https://android.googlesource.com/platform/frameworks/volley
Cloning into 'volley'...
remote: Counting objects: 164, done
remote: Finding sources: 100% (164/164)
remote: Total 3222 (delta 307), reused 3222 (delta 307)
Receiving objects: 100% (3222/3222), 1.22 MiB | 114.00 KiB/s, done.
Resolving deltas: 100% (307/307), done.
Checking connectivity... done.
~/git/Sandbox/android/AndroidGetJSON $ ls volley
Android.mk build build.xml pom.xml
proguard-project.txt src bintray.gradle build.gradle
custom_rules.xml proguard.cfg rules.gradle volley.iml
Your build.gradle for the module/library could be as simple as:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If your module is just a collection of .java POJO classes.
If it's model / entity classes and you're using annotations and have some dependencies you could add those in:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
repositories {
mavenCentral()
}
dependencies {
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-jdbc:4.48'
}
This happens when you are compiling imported or copied folder/project as module in libraries folder. This issue was raising when I did not include the build.gradle file. when I added the file all went just fine.
For me it turned out to be an relative symbolic link (to the referenced project) that couldn't be used by grade. (I was referencing a library). Thats a pretty edgy edge-case but maybe it helps someone in the future.
I solved it by putting a absolute symbolic link.
Before ln -s ../library after ln -s /the/full/path/to/the/library
I also faced the same issue and it resolved by changing one flag (gradle.ext.set("allowLocalEdits", true)) to false in settings.xml.
For me, one of dependent library does not exist in correct path, but the error message does not point THAT library correctly.
For example, what I missed is :library-3 but the error throws at :library-1.
poor gradle.
Try adding Volley library and sync and run the program. if one has pulled and i has volley usage and the error shows as -Android Studio Gradle Configuration with name 'default' not found then follow the step of adding the volley library in your gradle. hope it helps. I cleared my problem this way.

Categories

Resources