Tango sample apps on Android Studio, with Gradle - google-project-tango

Does anyone know a way to import the Java Tango samples (https://github.com/googlesamples/tango-examples-java) in Android Studio, and configuring correctly the build with Gradle ?
I've been able to import them in Android Studio, via "Import Project...", compile them and install them on the Tango tablet, but without using Gradle.
Any ideas ?

There is a git project which already migrates the samples to Android Studio - https://github.com/briangriffey/tango-examples-java

I think what you are asking for is the correct setup to let Gradle work for you.
For this you need to create a build.gradle file in your app's directory if the import did not do it for you. The build.gradle should look like this:
apply plugin: 'com.android.project'
android {
compileSdkVersion 16
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 17
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/MyJar.jar')
}
With the corresponding values for SdkVersion, buildToolsVersion, minSdkVersion and targetSdkVersion.
In the "dependencies" block you can list all your jar-dependencies with :
compile files('libs/thejar.jar') or compile fileTree(dir: 'libs', include: ['*.jar']) if you have multiple jars.
Secondly, if it was not automatically created, you would need two files settings.gradle and build.gradle a the top-level of your project.
settings.gradle should contain:
include ':app'
assuming your app name is 'app'.
and build.gradle should contain:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Once you have this all in your project, you can use Build>Rebuild Project to make Gradle build the project for you.

Just as a follow up here, Tango c examples has been migrated to Android Studio project, you should be able to import directly to Android Studio now.

Related

Could not find play-services-basement.aar

Yesterday I tried building my app and everything worked fine.
Today, without any changes to the project... All of a sudden I'm greeted with this warning message telling me:
Error:Could not find play-services-basement.aar (com.google.android.gms:play-services-basement:11.0.1).
Searched in the following locations:
https://jcenter.bintray.com/com/google/android/gms/play-services-basement/11.0.1/play-services-basement-11.0.1.aar
Is anyone experiencing the same sort of issue?
If you follow the link where it's searching for the package it basically gets downloaded instantly through the browser. I suppose something has changed on the server side? Perhaps naming conventions?
It looks like it's looking for: play-services-basement.aar and fetches play-services-basement-11.0.1.aar instead?
Could this be a naming convention or gradle issue?
jcenter() has had mirrors of some libraries (I guess they are doing intentionally) that should originally available through google() or maven() repositories. When gradle build works, for any library that is used in the project the first place to look for is the repository that is listed first in repositories {.. When the jcenter() mirror does not have the release (e.g com.google.android.gms:play-services-ads:15.0.1 for my case) your gradle is looking for, the build fails with such error.
So, jcenter() should be listed at the last place in repositories {.. parts as below.
buildscript {
ext.kotlin_version = '1.2.50'
repositories {
google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}...
and
allprojects {
repositories {
google()
jcenter()
}
}
This is crazy!!! I faced the same issue. The builds were working fine and then suddenly started to fail with the same issue. I tried the suggestions above but it didn't work for me. Finally, this is what worked for me:
Update to latest firebase dependencies:
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-ads:17.0.0'
also, the ads services:
implementation 'com.google.android.gms:play-services-ads:17.0.0'
Note: with play-services-ads:17.0.0, it mandatory to add the following in the Manifest file, otherwise application crashes on opening.
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>
</application>
UPDATE #2 2018/05/29
The issue looks to be fixed gone now, and I'm still using the same gradle configs. But I did these steps a while ago I'm not sure if these did anything or if this is a server-side issue and it got fixed/updated recently. I just noticed the issue was gone after I did the following steps:
Add the following in project-level gradle.build's buildscript > repositories and allprojects > repositories.
google()
maven { url 'http://jcenter.bintray.com' }
Change the google-services classpath to classpath com.google.gms:google-services:4.0.1'
Sync Project with Gradle Files
UPDATE #1 2018/05/29
I got around the error by downgrading my firebase dependencies to ~12.0.0 in the app-level gradle. But this will severly impact the app, still looking around for more feasible workarounds.
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
...
compile 'com.google.firebase:firebase-core:12.0.0'
compile 'com.google.firebase:firebase-database:12.0.0'
compile 'com.google.firebase:firebase-storage:12.0.0'
compile 'com.google.firebase:firebase-auth:12.0.0'
compile 'com.google.firebase:firebase-crash:12.0.0'
...
Same here, I have experienced the same issue described by #SimbaClaws. Everything was compiling smoothly until I faced the same issue yesterday.
I have the following codes in my project-level build.gradle,
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.google.gms:google-services:3.2.1'
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And the following codes for the app-level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "my.secret.application"
minSdkVersion 16 // 19
targetSdkVersion 26
versionCode 1
versionName "5.0.204"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.firebase:firebase-core:15.0.2'
compile 'com.google.firebase:firebase-database:15.0.0'
compile 'com.google.firebase:firebase-storage:15.0.2'
compile 'com.google.firebase:firebase-auth:15.1.0'
compile 'com.google.firebase:firebase-crash:15.0.2'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.android.support:palette-v7:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'org.greenrobot:eventbus:3.1.1'
testCompile 'junit:junit:4.12'
compile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
}
apply plugin: 'com.google.gms.google-services'
Can anyone advise if I missed anything? I'm also still looking around for possible workarounds and answers. TIA!
Had same issue, for me none of the answers mentioned here worked. So I just updated dependencies in the gradle file and whichever dependency had com.google.gms: (kept them at same version example 16.0.0)
I have also experienced this issue. The root cause, I found out was that there inconsistent build Gradle version.
In the Gradle Scripts repository "if I can call it that " there are two build gradle modules. The build.gradle (Project: name of app) and the build.gradle (Module: app). Make sure that classpath 'com.android.tools.build:gradle:3.2.1' in dependencies is using the latest and same version of the tool. Inconsistencies result in issues with the build.
In my case just added www earlier url was like url "https://jitpack.io/" after this added www started working for me. In other repositories also try to add explicit URLs.
maven {
url "https://www.jitpack.io/"
}

Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:27 [duplicate]

i try to add recyclerview to my project and get this error appear and i added it from android studio dependencies
Starting from version 26 of support libraries make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint.
Something like;
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
This is how I have it working.
Add maven { url "https://maven.google.com" } as #Gabriele_Mariotti suggests above.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Then on the build.gradle file inside the App folder add
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 26
}
Then on the dependencies use
dependencies {
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:cardview-v7:26.0.1'
}
If you are using Android Studio 3.0 or above make sure your project build.gradle should have content similar to-
buildscript {
repositories {
google() // add google() before jcenter()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google() // add google() before jcenter()
jcenter()
}
}
And for below Android Studio 3.0 and starting from support libraries 26.+ your project build.gradle must look like this-
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Note- position really matters add google() before jcenter()
check these links below for more details-
1- Building Android Apps
2- Add Build Dependencies
3- Configure Your Build
Just add this to your main all project level build.gradle file under allprojects()
maven {
url "https://maven.google.com"
}
I face the same problem while I have updated my SDK and Android studio version(3.0 beta). I have solved this problem going through this tutorial. In this they told us to update are build configuration file like
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android 8.0
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Hope it will help you out.
in may case I found OneSignal changed their dependencies
so I changed it from
compile 'com.onesignal:OneSignal:[3.5.8, 3.99.99]'
to
compile 'com.onesignal:OneSignal:[3.5.8, 3.5.8]'
then it works, please check any unspecific dependency.
Add this to the project level build.gradle file and it should work fine.
allprojects {
repositories {
google() // this is to be added if there's something already.
jcenter()
}
}
Google's new Maven repo is required for the latest support library that is compatible with Android 8.0.
Just update your Google's Maven repository like below:
To add them to your build, add maven.google.com to the Maven repositories in your module-level build.gradle file:
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Alternative you can update build.gradle file like this:
repositories {
jcenter()
google()
}
Then add the desired library to your dependencies block. For example, the cardview library looks like this:
dependencies {
compile 'com.android.support:cardview-v7:26.1.0'
}
in sdk 28
u can use
implementation 'com.android.support:design:28.0.0'
and remove cardView library
Update your Android Support Repository from sdk manager.
There is another way to add google repository
Add gradle-4.1-rc-1-all in gradle-wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Then add google() in the top-level build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
Simply change the build-version from
compile 'com.android.support:appcompat-v7:26.0.0'
to
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
This will solve your problem.
If the other solutions here do not work, make sure you are not in 'offline' mode. If enabled, android will not download the required files and you will get this error.
try to compile
compile 'com.android.support:cardview-v7:25.3.1'
Clean your gradle from terminal
./gradlew clean
then use this code in your build.gradle section
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Make sure, your included library version is available. For your checking, you can use this link
I had this issue when creating a new project in Android Studio using Kotlin. The way that finally helped me:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
google()
jcenter()
}
}
Ionic 4, opened /platforms/android/platform.properties, changed the version of the listed library throwing the error (in my case, com.android.support:support-v4:27.+) to:
com.android.support:support-v4:28.+
Use compile 'com.android.support:cardview-v7:25.4.0'
If you want version 26 you should use compile 'com.android.support:cardview-v7:26.0.0-beta2', because it is beta for now
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.test"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
this is working for me
compile 'com.android.support:cardview-v7:+'
This should pull the most recent version, and allow it to compile.
try this,
goto Android->sdk make sure you have all depenencies required . if not , download them . then goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
May be this problem is due to facebook library.
Replace
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
by
compile 'com.facebook.android:facebook-android-sdk:4.26.0'
#Aryan is correct Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)
A picture worth thousand words
2 Steps to fix this..
1, connect to internet.
2, Click on clean project. this will fix it
:)
For me I just had to clean my project.
Build -> Clean Project
Another time I had to:
File -> Sync Project with Gradle Files.
When you sync this dependency to the android studio:
implementation 'com.android.support:cardview-v7:26.0.1-alpha1'
Then, Sync the Gradle with Project Files.
It will say, (Suppose if you are working on new ones like androidx) obviously, it will show error on the dependency.
For that you can go to the File menu and click on the invalidate/restart the code. It will resolve itself and the application will restart without any error.

Gradle 'Build Script error' occurs when I attempt to use testCompile in dependencies

I'm working with Android Studio and in my dependencies for my application I attempting to add a testCompile dependency as listed here: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
When I sync my file I get the error:
I don't understand what is going on, my gradle build file in my root folder is set to classpath 'com.android.tools.build:gradle:0.12.+' and that's the most recent version. Why doesn't it recognize testCompile? I don't want to deploy test dependencies to production... Any helps would be appreciated.
EDIT: Here is the project build file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and here is the src build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.edu.myApp"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/scribe-1.3.5.jar')
compile files('libs/json_simple-1.1.jar')
compile 'com.google.android.gms:play-services:5.0.77'
// Can't be higher than 19 if we want to support smaller android versions
compile 'com.android.support:appcompat-v7:19.+'
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:19.+'
// This Mockito includes all dependancies (great for us)
testCompile "org.mockito:mockito-core:1.9.+"
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.objenesis:objenesis:1.2'
}
You should use androidTestCompile, not testCompile. If this is due to modifying the dependency scope via the Project Structure dialog, then there's a bug where it uses the wrong statement to set up the dependency. I've filed https://code.google.com/p/android/issues/detail?id=74771 for this.
I stumbled upon this post a year later. I was having this problem because I inherited an older project that was using an out-of-date Gradle build tools setting in the Gradle build file. I fixed this problem by updating Gradle build tools, which you need to do apparently by incrementing the version number in the Gradle build file:
dependencies {
classpath 'com.android.tools.build:gradle:1.X.X'
}
where X.X is the latest gradle build tools version number. Right now I'm using Android Studio v1.2 and I've got my build tools version number set to:
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
}
I came across this problem when I was trying to implement unit tests, which are now built-in to Android Studio apparently.
Hope this helps someone with the same problem.
I got this "method not found 'testcompile()'" error also. The problem was I had testCompile 'junit:junit:4.12' in my project build.gradle file and not in by app build.gradle file. How could I have known it was in the wrong file? The project file only states "NOTE: Do not place your application dependencies here; they belong in the individual module build.gradle files". Such a simple answer no wonder I couldn't find it.
I have a library project. I believed the Android documentation and put the testCompile statement in my top level build.gradle file. Turns out it actually had to go in my module build.gradle file.

Gradle deprecation "Relying on packaging to define the extension of the main artifact..." in Android Studio project can be fixed?

I'd like to learn how to use Android Studio at the best, but I still have limited experience especially in building with Gradle.
Executing tasks: [clean]
Relying on packaging to define the extension of the main artifact has
been deprecated and is scheduled to be removed in Gradle 2.0
:app:clean UP-TO-DATE
BUILD SUCCESSFUL
Even if everything works I would like to avoid using deprecated methods;
I state that I see this question and tried to understand the deprecation message but fairly the focus for me now is understanding building APK on Android Studio and how to put hands in a project created by this IDE.
Is it possible to fix-it by changing something (configuration files or artifacts) in the project?
PS: I'm on "Android Studio (preview) 0.4.3 build 133" and in the project there is two build.gradle:
1) ~/AndroidStudioProjects/MyAppProject/app/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
2) ~/AndroidStudioProjects/MyAppProject/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
and one settings.gradle
~/AndroidStudioProjects/MyAppProject/settings.gradle
include ':app'
This appears to be a bug in the Android Gradle plugin and not something you're doing wrong; I see it coming up any time you include a dependency in one of your modules even if it's specified correctly. This warning isn't anything to worry about.
I've filed https://code.google.com/p/android/issues/detail?id=65501 about this.

How to properly setup Gradle in Android Studio for ActionBarSherlock?

So I'm struggling to setup a very simple Project in Android Studio v0.2 with Gradle v1.6.
I want to create a simple app that uses ActionBarSherlock, so I created a Project in Android Studio.
In the same root folder as the Project is created, I have downloaded the latest ABS.
So here's my structure:
|ABSAppProject
|..settings.gradle
|..build.gradle
|--ABSApp
|....build.gradle
|actionbarsherlock
|..build.gradle
In the root settings.gradle, I have:
include ':ABSApp'
include 'actionbarsherlock'
project(':actionbarsherlock').projectDir=new File('actionbarsherlock')
In the actionbarsherlock/build.gradle I have:
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
dependencies {
compile 'com.google.android:support-v4:r7'
}
android {
compileSdkVersion 14
buildToolsVersion '17'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
And, finally in, the ABSApp/build.gradle, I have:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:r7'
compile project (':actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
}
The root build.gradle is empty.
When building, (using gradle build --info) I get:
Starting Build
Settings evaluated using settings file '/Users/m/Documents/Projects/ABSAppProject/settings.gradle'.
Projects loaded. Root project using build file '/Users/ma/Documents/Projects/ABSAppProject/build.gradle'.
Included projects: [root project 'ABSAppProject', project ':ABSApp', project ':actionbarsherlock']
Evaluating root project 'ABSAppProject' using build file '/Users/m/Documents/Projects/ABSAppProject/build.gradle'.
Evaluating project ':ABSApp' using build file '/Users/m/Documents/Projects/ABSAppProject/ABSApp/build.gradle'.
Evaluating project ':actionbarsherlock' using empty build file.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':ABSApp'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
Building the ABS library alone using Gradle seems to work ok, so that gradle.build file is probably ok.
What am I doing wrong?
There is no need for downloading ABS separately. Gradle supports Android's new .aar format which makes using library projects easier. Just add this (or whatever version it is currently) to dependencies section in build.gradle of your project:
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
and let Gradle handle the rest.
The entry for actionbarsherlock in settings.gradle should be
include '..:actionbarsherlock'
you should not need project(':actionbarsherlock').projectDir=new File('actionbarsherlock')

Resources