I'm trying to import this as a library in a project I'm working on in Android Studio:
https://github.com/d4rken/myolib
I cant workout exactly how to do it. even before I try to do this, I tried to open the project using new->Import project-> (selecting the settings.gradle). This then complained about not knowing about:
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
So I tried adding these manually using the advice on:
Importing github projects as library to existing project
Adding external library in Android studio
But its still complaining about no cached version for offline mode. If I do disable work in offline mode then, well it just sits there forever. I want to give it everything manually because in my experience disabling work in offine mode usually doesn't help.
I completely understand this isn't a new topic on Stackoverflow. The issue of how best to import libraries as .jar, .aar, .os etc. etc has been covered a few times. And yet most answers are subtly different and some work sometimes, others work other times.
Does anyone know of a detailed explanation about how I should achieve this ?
If anyone has been successful in importing this project and using its libraries I will be eternally grateful if you could tell me how you achieved such wizardry.
You import the library through your app's build.gradle file. An import section looks something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v13:24.1.1"
}
So to import the library you just linked, you would simply add this line to your dependencies section, as per the readme:
compile 'eu.darken.myolib:myolib:0.0.4'
Related
I am trying to work on a sample project to learn MvRx. However, seems something is wrong. Android Studio is not able to find and import activityViewModel automatically.
1) I tried to import it manually by writing its package name but it is still gray.
2) From Gradle tab, I selected my root project and clicked on Refresh Gradle Project in order to refresh all dependencies. It did not help, too.
What is the problem?
If someone is getting same error even when using activityViewModel() in fragment, this answer may be helpful.
In my case I was using activityViewModel() inside fragment. Still I was getting this as well as many other errors. Finally I figured out that mvrx is now using kotlin coroutines and all dependencies on rxjava are removed in 2.0.0-beta1.
To solve this use
implementation "com.airbnb.android:mvrx-rxjava2:2.0.0-beta3"
in place of
implementation "com.airbnb.android:mvrx:2.0.0-beta3"
in dependencies section of your build.gradle.
Your feature code must be in a Fragment (that extends BaseMvRxFragment), not in an Activity.
Because you have other com.airbnb.mvrx. references that have resolved correctly, it means you do have a reference to the com.airbnb.mvrx library. However, it is likely that you have a different version of the library referenced than the sample's original author. Look in your build.gradle file for dependencies and see if you have the library referenced there. If so, compare its version to the one in the sample, if different, then modify your reference to the sample's version number. If not, then add a reference to the library with the appropriate version number of the library where that object exists.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.airbnb.mvrx:mvrx:12.0.1'
}
I'm migrating from Eclipse over to Android Studio and am looking at the Navigation Drawer example from Google. Right away, I see that I get this warning;
It looks like I need to use the v7 library rather than the v4. I can't figure out how to do this. In Eclipse, I just added a dependency from the build tools, but I see no such option in Android Studio. If I look at the build.gradle file, I can see this:
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
I just downloaded Android Studio yesterday, so I think that I should have this dependency somewhere, but I just don't know how to include it. Can someone tell me how to do this?
From within Android Studio, you can go to File, Project Structure, select your module, and go to the Dependencies tab - you'll see a list of dependencies - you can add new dependencies via the + sign near the bottom of that screen - it will automatically suggest the most popular libraries and all Google libraries including the one you want: appcompat-v7. This controls the build.gradle file and, in your case, adds the line:
compile 'com.android.support:appcompat-v7:21.0.3'
Note that you can also use sites such as Gradle, please to manually figure out what the dependency should be and add it to your build.gradle file yourself if you'd like.
In my project, i have a module abc:
//abc module (lib) dependency
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
And my app's dependency:
dependencies {
compile project(':abc')
}
And the errors are:
“Attribute ”mnp“ has already been defined”
“Attribute ”xyz“ has already been defined”
...
And i found that all these attributes are defined in declare-styleable of module abc and they are quite a lot. I dont know where they produce the duplicate since i can run normally from Eclipse, not Android Studio. Some suggests that to manually rename the attributes of those but I think it is time consuming.
Any better solution? Thank you!
This happens to me as well when I import project from Eclipse. Android Studio seems to binds library project even thou there was an error adding library modules.
I can usually fix this by firstly delete library modules, then opening Project's settings.gradle file and delete imports from there. After this, import of library modules works well.
And when I have issues with styleable file, I can usually fix this by setting SDK version to at least 20 (Android 5.0)
I'm a newbie to Android Studio IDE. I used to implement Android application, using Eclipse IDE. As a beginner in Android Studio, I tried this lesson from YouTube to include a external jar file to my project and use it. But unfortunately I'm unable to use that library even though the Gradle or Android build doesn't throw any error/exception when compile and run.
I've seen related questions from SO too. As an example, I've tried out things that discuss in this question.
In the build.gradle file, I used
compile files('libs/jsoup-1.7.3.jar')
and next time used
compile fileTree(dir: 'libs', include: '*.jar')
Neither work for me. After editing that build.gradle file, I used Sync Project With Gradle Files tools and also command line clean
gradlew clean
too. No error/exceptions, but when I try to write Docu... in my MainActivity class it doesn't show the import option org.jsoup.nodes, but show other imports options. What could be the mistake I've done.
There were some bug in 0.4.2 related to dependencies management, do upgrade your studio to 0.4.3 will solve your problem .
I think I've tried everything now...
I've been all over stack overflow, I've even consulted the android doc
Most of the posts here show how to add the .jar file in Eclipse "android tools -> add support library" or something
So I've tried to do it how the doc tells me, by going to build.gradle, and adding compile 'com.android.support:support-v4:19.0.0' to the dependencies
but even if I add it, and rebuild the project, I still can't import android.support.v4.content.LocalBroadcastManager... it doesn't even know what android.support is...
So is there anyone who can help me with this? the issue is getting very annoying, and it's slowed me down by hours...
Edit: I have updated the Android SDK, and made sure that the library exists in the sdk folder, so I know it's there... I just can't make android studio add it for some reason...
Edit 2: Only by navigating to the exact file path, manually, and then copying said path I was able to access the file... Still, I'd very much like to know what I can do to make this a more painless process...
Make sure your library got added successfully.
Check the following things.
1.Your build.gradle should be like
dependencies {
compile 'com.android.support:support-v4:19.0.+'
}
2.File > Project Structure > Modules >Dependency Tab
There should not be any red mark in dialog showing error if they are fix them.
3.Check your Module_Name.iml file
It should have this entry in last section
<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project"/>
If its there with no entry close you studio delete .iml file and open studio again wait for gradle sync to be complete.You .iml file will be created again check for entry.
If every thing is fine do sync Your project with gradle again using this lovely tiny gradle button in toolbar.
Try adding one of those dependencies to your app level build.gradle :
AndroidX
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
Support Library
implementation 'com.android.support:localbroadcastmanager:28.0.0'
Then sync project with Gradle files.
After lot of searching and R&D i found some solution. This is working for me i hope this is helping you.
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
If you not use Androidx please add this line
implementation 'android.legacy:legacy-support-core-utils:1.0.0'