How to integrate MoPub inside a shared library in Android Studio - android

I need to integrate MoPub inside an android library shared by 3 different games.
I tried to use the fabric plugin with no success... after some attempts I get this error:
Error:Failed to resolve: com.mopub.volley:mopub-volley:1.1.0
Then I also tried to follow this guide that you can find here (https://github.com/mopub/mopub-android-sdk/wiki/Getting-Started) but I always get some errors (I can't execute the gradle command via terminal or I get the same error as mentioned above).
Can someone help me?
Thank you,
Mirko
UPDATE
Thanks to #Edward I was able to import correctly mopub-sdk in my project.
In order to fix the mopub-volley error, first clean the solution, read which files are missing in the console, look at the path, recreate the indicated path and add mopub-volley-1.1.0.jar, mopub-volley-1.1.0.pom in that folder.
Rebuild and you are ready to go!
In my case, mopub-sdk was looking for the mopub-volley lib inside an
inexistent folder in the same path of the android sdk.
If you get another error related to the millenial sdk, add this line in the dependencies section of the build.gradle file inside the mopub-sdk library:
compile fileTree(dir: 'libs', include: ['*.jar'])
you should get something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:support-annotations:22.0.0'
compile 'com.mopub.volley:mopub-volley:1.1.0'
}
Hope this can help you!

Go download the MoPub SDK.
Unzip and you will get a mopub-sdk folder
Navigate to your ‘Project location’, go into your project folder, and drop the unzipped mopub-sdk into the folder.
Navigate back to Android Studio and open your project's settings.gradle file and include the MoPub SDK as a module as shown below. You may need to sync Gradle again in Android Studio to have the ‘mopub-sdk’ show up in the left Project window.
include ':app', ':mopub-sdk'
Open your project's build.gradle file and add jcenter as a repository and the MoPub SDK as a dependency:
repositories {
jcenter()
}
...
dependencies {
compile project(':mopub-sdk')
...
}

For those late to the party:
repositories {
jcenter()
}
dependencies {
compile('com.mopub:mopub-sdk:4.8.0#aar') {
transitive = true
}
}
just make sure you've added jcenter() in the your repositories. fabric does not do this automatically for some reason

It looks like there is no mopub-volley lib into mavencentral or jcenter
So tou can try to use
compile 'com.mcxiaoke.volley:library:1.0.18'
instead of
compile 'com.mopub.volley:mopub-volley:1.1.0'
It helps for me.

Related

How do I know that I've imported a jar properly in AndroidStudio project

I'm trying to use a third party library in AndroidStudio and am having some problems, it is the JSch library.
What I did was download the ".jar file
On my app within Module Settings I added it
And then selecting the app module again I added it within the dependencies
Yet when I try to code it into my files through "import com." it does not show.
I am too new at this to know if I added it incorrectly or if it has a problem within the ".jar" file.
Does this ring a bell with anyone who might know what I am doing wrong?
Just follow this steps:
1.- Put the jar into the libs folder
2.- Right click it and select "Add as library"
3.- Check that your build.gradle file contains:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
You'll provably need to do a clean build
Add library to yours app dependencies:
dependencies {
// Other libraries...
compile group: 'jsch', name: 'jsch', version: '0.1.29'
}
And synchronize your gradle.

Compile Twitter4j with gradle

I'm trying to use the twitter4j library. And I saw on their website that you can use Maven to integrate it.
So In my gradle.build file I did
buildscript {
repositories {
mavenCentral()
jcenter()
}
and compile:
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile 'org.twitter4j:twitter4j-core:4.0.3'
}
}
This doesn't seem to do the trick. I can't use any of the classes from twitter4j even after cleaning and refreshing everything. What I'm concerned about is that I downloaded the twitter4j-4.0.3.zip and extracted it , but I never placed the folder or it's content anywhere? Feels like i'm missing something?
I faced this kind of issue few weeks back when i try to utilize Twitter4j library through Gradle.
What i did was,
Downloaded the Twitter4J zip file from their site.
Open the extracted folder and there you will find lib folder. Open it.
You will find some .lib files like twitter4j-core-4.0.3.jar. This file core is important and you need to add remaining .jars when you use that application. If you're not sure, then copy all .jars and paste it in libs folder.
Then click File -> Project Structure -> Select app in the left column -> choose Dependency Tab.
Click + in right top and choose File Dependency then select the jars in libs folder.
6. Click Ok and you're done.
Good luck :)
Even I faced the similar problem recently and adding it like this to the gradle dependencies seems to work for me:
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.7'

Installing MPAndroidChart into Android Studio

I first tried using "Project Settings" and importing .jar -- however then only the .jar file is visible in the left pane.
And I in "Project Settings" try to import as a project I get Gradle sync errors.
Is it possible to install in a way, so I can browse the source code files while also using them in my android project?
Add Repository and dependency like this:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
//format for including lib jar files for all flavors
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':baselibrary')
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
}
You can use the library via gradle or maven. If you are having problems, I suggest you read tutorials in that direction.
If you want to browse the source code, you should clone the git repo of the library and reference the library project in your android studio project:
How do I add a library project to Android Studio?

Adding Parse-1.8.0 to Android Studio 1.0.1 (Or any .zip file)

So there seems to be a few threads that attempt to explain how to add .zip files to android studio but I am making no progress. I am migrating from eclipse so perhaps that is why I am so incompetent in figuring out how to perform this task. Can someone please explain how to add external libraries to Android Studio v1.0.1? In eclipse it was simply importing jar/zip and done.
I was in the same situation, trying to integrate Parse 1.8 with Android Studio 1.0.2.
On Parse's instruction page, it simply tells you to import the library into Android studio, which isn't too detailed. Here is how I solved this problem.
Choose to import from a "Non Android Studio Project", right when Android Studio starts.
When it asks you to choose the project, give the path, on Windows e.g.C:/path/to/parsesdk/. On *nix systems, it should be to where you have extracted to it, /home/user/path/to/parsesdk.
After you choose the path, Android Studio will import the project accordingly.
Click on the Application root folder (the top most folder in the folder hierarchy to the left), right click > New > Package > and add it under the src folder, name is libs.
Copy paste the jar to the libs folder (I only copied the jar file, as I didn't need the other extra material)
Right click on the jar, there should be an option labeled as "Add as library" towards the bottom, click on that.
Android Studio will automatically add the following to the build.gradle file.
compile files('src/libs/Parse-1.8.0.jar')
Once the above step is completed, click on File > Project Structure.
On the left, there should be a section called "Modules", click on the "Dependencies" tab on the top.
Click the green "+" sign > Module Dependency
Select the module from the list.
Last thing, in the build.gradle file for the "ParseStarterProject" module, if there is a red line under the classpath, change it to the following
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
After completing this step, I was able to successfully build the app.
Hope this helps :)
If you are using gradle with android studio (which is the preferred way now) you can include jars in a folder using this code snipet from my build.gradle.
buildscript {
repositories {
flatDir { dirs 'c:\\path\\to\\folder' }
mavenCentral()
}
}
Or by including a single file in depencies like below.
dependencies {
compile fileTree(dir: 'a-folder-in-root-of-project', include: 'a_jar.jar')
}
This is the only way it worked for me :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile files('libs/Parse-1.9.2/Parse-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseCrashReporting-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV3-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV4-1.9.2.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0-javadoc.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0.jar')
}
OR
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'Parse-*.jar')
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'ParseCrashReporting-*.jar')

Use android-maps-utils in Android Studio

I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!

Categories

Resources