I've migrated an Eclipse example to Androidstudio gradle type project.
I've added twitter4j libraries to module build.gradle:
dependencies {
compile 'org.twitter4j:twitter4j:4.0.3'
compile 'org.twitter4j:twitter4j-core:4.0.3'
compile 'com.twitter:hbc-twitter4j-v3:1.4.2'
compile 'org.twitter4j:twitter4j-http2-support:4.0.3'
}
It's importing twitter4j classes, but not these ones:
import twitter4j.http.AccessToken;
import twitter4j.http.RequestToken;
It says cannot resolve symbol http
I've tried importing the twitter4j.http but nothing I just can't make it work.
I'm using:
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
Anybody can shed some light on this?
I've looked for hours but no solution yet :(
Thanks in advance!
AccessToken is in the twitter4j.auth package. I assume there is a similar problem with your other classes. It appears that the package structure has been rearranged from earlier versions. I suggest you bookmark the twitter4j JavaDocs and refer to them regularly.
Related
I'm wondering about this. I've been trying to import a library ("Time4J" Android version "Time4A") to a project in the Android Studio, and had to try a number of different things before getting it to "work". I finally managed to get it to import without errors, but now it crashes and doesn't want to work. Somehow I had managed to import it before and it worked without crashing, now I can't replicate that.
The problem seems to me that there's a lot of out-of-date information here about how to import libraries, and nothing for the most recent and up-to-date versions of the Android Studio system (so I was using like 2, 3, 4-year old stuff to try and make this work and this changes fast because there doesn't seem to be anything available from 2017.) and I suspect this is why it's not working. How do you correctly import a library in the newest 2017 versions (2.3.1 and up)?
The recommended way is to import libraries as Gradle dependencies. As described on the Time4A GitHub page:
dependencies {
compile group: 'net.time4j', name: 'time4j-android', version: '3.33-2017b'
}
Add this to your build.gradle and it will download and import the library.
First you'd better upgrade your build.gradle (Project) and add google() to buildscript and allprojects repositories.
Then you can add whatever dependency you want with new method called Implementation, as compile is deprecated.
dependencies {
implementation group: 'net.time4j', name: 'time4j-android', version: '3.33-2017b'
}
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'
So I'd like to import the "apache commons ftp" libraries for use in my project. I got as far as the importing the modules, and am including a pic just to show that they're in there.
But when I try to use the import statements
(i.e.) import org.apache.commons.net.ftp.FTP;
they fail.
So am curious if I am missing a step, or am missing something.
Please add below dependency in your gradle:
// https://mvnrepository.com/artifact/commons-net/commons-net
compile group: 'commons-net', name: 'commons-net', version: '3.5'
For any dependency to import in Android Studio through gradle use below reference:
https://mvnrepository.com/
This will save your time from importing module and solving gradle errors :)
Thank You
I would recommand AndiGeeky's answer if you don't modify so you have a custom library.
Meanwhile if you really want to use the library as a module, you can add this line in your build.gradle in your module app
compile project(':NAME_OF_YOUR_MODULE') << should be commons-net-3.5
Hope that will help you :)
I'm trying to create an app for android (google Tango) that uses thrift to send some information to a client. I take a sample Tango app which runs without Thrift. Then when I add try to add some of the Thrift dependencies (like slf4j-log4j12-1.7.12.jar) I suddenly get errors like
error: package com.google.atap.tangoservice does not exist
I don't get what's wrong, it worked before...
Why does this happen, and how can I fix it?
Thank you
UPDATE
The way I added the library was by clicking right on App>new>module then I chose import jar, and selected the jar. Then I went to project structure and in dependencies I added the module of the jar I imported.
Adding it like this did not help me resolve the conflicts I had before:
import org.slf4j.Logger;
giving me the error "cannot resolve symbol 'Logger'".
And it also introduced the errors previously mentioned.
Have you tried adding a dependency to your build.gradle file like this:
dependencies {
compile 'com.google.atap.tangoservice'
}
If you are using local jar dependency then add it like this to the build.gradle:
dependencies {
compile files('libs/something_local.jar')
}
I use Eclipse before changing to AS,but something really puzzle me.
I import the Smack4.1.4 into app/libs,and set the dependencies.
Everything looks OK without one exception.
Caused by:
java.lang.ClassNotFoundException: Didn't find class
"javax.naming.directory.InitialDirContext"
I have searched about it, it seems that javax.naming is not in android's whitelist.
So how could i use smack in AS? That's a big problem for me.
Could someone help?
What you need to do is to stop importing jar files and start using gradle to resolve the dependencies, that's a major difference in how you import libraries in Android Studio vs Eclipse, only import jars if they are not available from a repository:
https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide
Example:
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
dependencies {
compile "org.igniterealtime.smack:smack-android-extensions:4.1.0"
compile "org.igniterealtime.smack:smack-tcp:4.1.0"
}
OK, now I solve this problem.
Actually, I also need to import the following jar:
dnsjava:dnsjava
org.jxmpp:jxmpp-core
org.jxmpp:jxmpp-jid
org.jxmpp:jxmpp-util-cache
Hope my answer will help some beginners like me. :)
After 1 day i finally resolve this issue in nativescript android.
Dont add dnsjava.(version).jar , smack-java7-version.jar
Add smack-resolver-dnsjava-4.2.1.jar