When I upgraded AndroidStudio from 0.8 (or 0.9) to 1.0.2 AndroidStudio was not able to resolve my R file and suggests importing it (import my.package.R). I'm using SDK Tools 24.0.2 and SDK Platform-tools 21.
I've tried cleaning, resynching and rebuilding the project, as well as checking the layout files for errors, but I didn't find anything.
Another weird thing is that when typing "R.layout" AndroidStudio suggests either "android.R" or "my.package.app.R". When chosing the former I'm not able to use my layout files, when chosing the later it automatically imports "my.package.app.R"
When importing R a co-worker of mine is even able to run the app...
This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "my.package.app"
minSdkVersion 14
targetSdkVersion 20
versionCode 6
versionName '0.1.6'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I think it could be of use to some of you here.
Thanks!
Edit: I was told that it is perfectly normal to import one's own R class. Sorry for the inconvenience...
If is showing error (red signed) and is not compiling I'm pretty sure there is something wrong in at least one XML file (like a tag unclosed).
I had same kind of error in Android Studio , the reason it gives Red Mark is due to some small errors , ending or opening tags are not been properly closed or opened!
Related
I have this repository ( https://github.com/udacity/Just-Java/tree/Lesson_2 ) that I'm trying to import. I extract the folder from the zip file that I downloaded from there. Then I try to use "import project" function on Android Studio, but I am not sure which exact folder/directory to select for import. When I use the main directory I unzipped, it takes about half an hour to load it and then gives me an error saying "failed to find target with hash string 'android-24' in: [i]my appdata folder[/i]
I have very slow connection at the moment, so it takes ages to download this Android SDK Platrom 24. I am running the latest version of the Android Studio.
So the 'build.gradle' file (Assuming you are using gradle) would specify which is the target Android SDK.
Now I suppose you have some Android SDK and the corresponding build tools already installed. These would then not require a download. But then gradle requires an internet connection to actually search for libraries that it should download to satisfy the dependencies of the project.
Now once you have figured out which Android SDK and build tools you have, you can make the change in the build.gradle file. (This would be in the /app/). You would have to make an edit here.
compileSdkVersion 21 *replace with the version you have*
buildToolsVersion "21.1.2" *this should also start with the compileSdkVersion number*
Hope this helps!
This is your app module build.gradle file, change in this file according to what you have in your SDK.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24 // Change what SDK Version you have
buildToolsVersion "24.0.2" // Change buildTool Version
defaultConfig {
applicationId "com.example.android.justjava"
minSdkVersion 15
targetSdkVersion 24 // Change targetSDK, can be same as compileSdk
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.0' //Change appcompact version
}
I have imported a android source code from Github and while syncing the gradle process I have got an error
Error:(1, 0) Plugin with id 'com.android.application' not found.
Open File
This is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "activities.safepassbeta"
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
}
Try changing the classpath in the top level build.gradle file to 'com.android.tools.build:gradle:2.0.0-beta7' and the distributionUrl value in gradle-wrapper.properties file to https://services.gradle.org/distributions/gradle-2.10-all.zip.
Make sure that in the settings for gradle in the 'Build, execution and deployment' section, you have set the preference to 'Use default gradle wrapper'.
As the other answer described, try changing the classpath in the top level build.gradle file. The file you show is the application build.gradle, not the top level build.gradle file. For Android Studio 3, you can try using 'com.android.tools.build:gradle:3.0.1'. The problem is that the gradle dependency is not downloading properly, usually because of improper settings for the url to use to download gradle. This is a common problem. If the problem persists look into solutions for how to set up gradle, such as Manually install Gradle and use it in Android Studio
A quick-and-easy fix is to look at your previous projects which work on your IDE, look at what version of gradle they are using. If you use that version of gradle in this project it will most likely work.
However, the 'proper' solution is to set up the distributionUrl properly. Worst come to worst, if that does not work, you could also try manually downloading Gradle to use it in your project.
I picked up someone else's project and when I asked AS to run the project on my AVD, it pops me an error:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId 'ca.gggolf.aminutegolf'
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
I don't know what to do.. Everything else works fine and the app was working a couple of years ago when it was first made.
Enable multidex for your project. Add below line to gradle defaultConfig:
multiDexEnabled true
Also add multidex dependency to gradle's dependencies :
compile 'com.android.support:multidex:1.0.1'
Check your location address of exist project. if you use special character like :
( / | \ + = * ... )
In folder and sub-folders name, you should change it and check it out.
I changed my folder name from "UI/UX" to "UiUx" and its done :)
I'm back at this question simply because it got many views.
First, thanks all for the help. I managed to run the app by creating a new project on Android Studio and importing classes one at a time while making sure the code was still fine. Maybe creating a new project added some parameters that were not present in the older version of the project.
If someone has a better explanation, feel free to answer!
Check your lib versions. In my case it was old Realm plugin that was an issue.
Sometimes this error happens to me. I don't have any java compiler errors.
And seems this issue related to the build cache of a project.
So it can be solved like this
Build/Clean Project
Build/Make Project or Build APK
Build with below command, this command will point the exact point in source code where the compilation error is getting generated.
gradlew assembleDebug --stacktrace
Background
On Android Marshmallow, Google has completely removed the support of Apache HTTP client (link here) because it doesn't have good performance compared to the alternatives.
This might also be the cause for so many apps crashing on Android Marshmallow.
The problem
Google allows you to still use this API, just not as a built in one, by adding this line to the gradle file:
useLibrary 'org.apache.http.legacy'
So, this is what I did:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
And:
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
When I tried it, it compiled fine (no errors being shown, and I could run the proof-of-concept app, as it doesn't have any special code), but when I tried using some of the classes that I know that are part of the old API (like "HttpClient" class), I see that it doesn't allow me to do so.
I know it's not recommended to use this solution, but we must have the app ready to work there at least temporarily, till we work 100% on all of the things that should change for Android Marshmallow, and we don't want surprises in the form of crashes.
Here's a screenshot:
The question
Why does it occur? Did I use it correctly?
EDIT: reported about this issue here:
https://code.google.com/p/android/issues/detail?id=181474
Android Studio was complaining that org.apache.http classes like
org.apache.http.NameValuePair
org.apache.http.client.utils.URLEncodedUtils
were missing.
So I added org.apache.http.legacy.jar which is in
Android/Sdk/platforms/android-23/optional folder to to app/libs
I also added this line to my app.gradle file
compile files('libs/org.apache.http.legacy.jar')
But if you're using more libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
This resolved all my errors that were caused because google removed support of Apache HTTP client.
useLibrary 'org.apache.http.legacy' did not work for me until I upgraded the Gradle tools version in my main build.gradle file of my Android Studio project, as follows:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
Perfect solution here by running a simple file path check.
by running
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
getBootClasspath().each{File file ->
println file.absolutePath
}
}
}
You will get something like below
/Users/"yourname"/Development/android-sdk-macosx/platforms/android-MNC/android.jar
/Users/"yourname"/Development/android-sdk-macosx/platforms/android-MNC/optional/org.apache.http.legacy.jar
So there you go, the jar is there.For some reason it didn't get added to the project. but you can always add it manually I guess.
The answer above just helps the debug builds to run, and release builds that are utilizing gradle.
Insert this inside the application tag on the manifest file, on all project instances that uses the legacy apache classes:
<uses-library android:name="org.apache.http.legacy" android:required="false" />
This helps for those who are still using Eclipse and ant scripts during compile.
After many frustrating hours, the following worked:
1. Locate the apache jar.
It should reside somewhere like:
C:\Users\<yourname>\AppData\Local\Android\sdk\platforms\android-23\optional
2. Copy org.apache.http.legacy.jar to your libs folder.
Either right click on libs -> paste , or use your file explorer to navigate to the libs folder of your project and paste.
If you don't have a libs folder, as I did, make a new project and import all relevant files into their respective places.
3. Click ok
see this
4. Most important step: Right click on the apache folder and select Add As Library.
see this
Hope this helps someone get on with their life.
I know this is silly reason but at list try it...
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.Hope this work for you.
Legacy Apache library located in
[ANDROID_SDK]\platforms\android-23\optional\org.apache.http.legacy.jar
So you can copy it inside you project libs or just use
compile files("${android.getSdkDirectory().getAbsolutePath()}" + File.separator + "platforms" + File.separator + "android-23" + File.separator + "optional" + File.separator + "org.apache.http.legacy.jar")
in your /app/build.gradle
First you have to check that in your libs folder
Then add into your gradle file like this
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "info.tranetech.laundry"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1
compile 'com.android.support:design:23.0.1
testCompile 'junit:junit:4.12'
compile files('libs/android-async-http-1.4.4.jar')
compile 'com.google.android.gms:play-services:8.4.0'
}
Enable this in sdk/platforms/android-23/optional/optional.json
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Remove
useLibrary 'org.apache.http.legacy'
from the build.gradle and I also added this line to my app.gradle file
compile files('libs/org.apache.http.legacy.jar')
But if you're using more libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
CoPLaS answer fixed my problems.
How to use the legacy Apache HTTP client on Android Marshmallow?
To continue using Apache HTTP classes for API 23+:
First of all, be sure to add the gradle dependencie into the build.gradle f
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
Then add the reference inside build.gradle of your project:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
A simple way to solve this issue is C:\Users\username\AppData\Local\Android\sdk\platforms. Here delete your android-23 and from SDK manager update your API 23 again. It will solve your issue.
I am using Android studio but this may be a general Intellij question (I'm used to eclipse). This seems like it should be super simple, but I can't figure it out.
I want to be able to run either module in my project independently, which is from what I understand the purpose of a module. This has worked fine until now when I want to call code from my "app" module in my "testmodule" module. Android Studio lets me import the code I need with no problems until I try to build the module. Then I get the expected "package not found" error. So then I try adding this in my "testmodule" build.gradle:
main.java.srcDirs '../app/src/main/java'
This causes two package import statements in my "app" module to fail. One of the failing packages is the package defined in my "app" manifest and the other is specified in my "app" build.gradle
sourceSets {
main.java.srcDirs += '../../connectorAPI/trunk/src'
}
I also tried to make one module depend on another but from what I've read in stack overflow (and the vague Android Studio error) one module must be a library file. This obviously doesn't work since I want to be able to run either. I would love to just copy the code I need but then I'd need to change both every time in version control, which is a nightmare.
In eclipse all you have to do is right click and link source. I can't imagine this is impossible or even out of the ordinary, so I must be missing something simple... can someone please help me out?
build.gradle testmodule
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.XXXXX.testmodule"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
}
build.gradle app
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.XX.XXX.XXX.XXX"
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main.java.srcDirs += '../../connectorAPI/trunk/src'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:+'
// Add the ArcGIS Android 10.2.5 API
compile 'com.esri.arcgis.android:arcgis-android:10.2.5'
compile 'com.googlecode.json-simple:json-simple:1.1'
}
I might be late by a few years but here is what I would do : Declare both modules as library, and create another two as application. Then you can easily import the two libriaries while still having two applications, if that is what you want.
As for the duplicate dependency issue that will arise, you can just add an exclude statement in the build.gradle respectively.