I'm using Android Studio to build a Glass app, with my SDK Manager updated to GDK Preview API 19 Revision 9, and my device is on XE 21.3. I'm trying to use the new CardBuilder class, but it isn't available. I can still use the deprecated Card class, but the new stuff just won't show up.
I even uninstalled/reinstalled the Android 4.4.2 packages, but nothing. The same occurs when I load the project in Eclipse, too. I'd like to not use the Card class, as this is for a demo tutorial.
Got any tips on how to force this?
It took me several minutes before Android Studio was able to recognise the new class. You shall delete the build folder and start a clean compilation. There is a problem with classes already compiled with previous version of the GDK which are not noticed for recompilation.
Mine finally got repaired...today's Android SDK update to 23.0.5 seemed to do the trick...that and playing with the External Libraries menu in the Project panel to make sure the new class was available and then manually adding the namespace. Whew.
Thanks for your help everybody! :)
I thought it might be that but it's the same as the Google SDK Sample Projects, but here's what I've got:
apply plugin: 'com.android.application'
repositories {
jcenter()
flatDir {
dirs 'prebuilt-libs'
}
}
android {
compileSdkVersion 'Google Inc.:Glass Development Kit Preview:19'
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 20
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
This is why I've stuck with Eclipse for Glass development. Android Studio has been too flaky again and again... I do use Android Studio for standard Android development
Related
I am trying to build a template of a Multiplatform library module in Android studio that can interoperate seamlessly with other normal Android library and application modules. I've found it's easy enough to make a Multiplatform Android project technically work in terms of compiling, running and publishing artefacts, but one problem I can't seem to solve is getting the source sets to show correctly in the Android project files pane view.
So you can see in the Project view here, the sources are divided into android, native and common directories and their respective test directories, for a total of six source directories:
In the Android Project view this is rendered by build targets instead of source file directories, so that this 'typing-sdk' module example has total of 10 different sub-modules. And you'll notice androidMain and androidTest are not among them: instead of being rendered as submodules, their sources fall under an inline kotlin directory instead; you can see the main and test com.demo.typing packages respectively.
It is a little annoying that every single build target gets its own submodule, when in practice, one will virtually never actually need to use some of these, like 'iosArm64Test' for example. Nevertheless, I can live with redundant submodules. The central problem here is that each of these submodules are populated with the wrong source files.
So whereas in the file structure, both the common and native sets have their own source files, as you can seen here:
In the Android Project View, every single submodule contains the Android sources!?
Either this is a bug in how Android Studio interoperates with the Kotlin Multiplatform Gradle Plugin, or there's something wrong with the Gradle build file I have written, which is this (using Gradle 7.1):
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.6.10'
id 'com.android.library' version '7.0.4'
}
allprojects {
group = 'typing'
version = '1.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
google()
}
}
kotlin {
android()
ios()
sourceSets {
commonMain
commonTest
androidMain {
dependsOn(commonMain)
}
androidAndroidTestRelease
androidTest {
dependsOn(commonTest)
dependsOn(androidAndroidTestRelease)
}
nativeMain {
dependsOn(commonMain)
}
nativeTest {
dependsOn(commonTest)
}
iosMain {
dependsOn(nativeMain)
iosX64Main.dependsOn(it)
iosArm64Main.dependsOn(it)
}
iosTest {
dependsOn(nativeTest)
iosX64Test.dependsOn(it)
iosArm64Test.dependsOn(it)
}
}
}
android {
compileSdk 31
defaultConfig {
minSdk 23
targetSdk 30
}
}
I have noticed most of the source examples already out there are using Kotlin DSL, which is preferable, but circumstances are forcing me to use Groovy here. On another project I have that is Kotlin DSL, using earlier versions of the Gradle (7.0.2) Android Gradle Plugin (7.0.2) and Kotlin (1.5.20), the Android project view is rendered differently, and though still quite defective, it's not so disastrously wrong as to have Android sources listed under every single build target module. In the Android block on that project you have a second definition of the sourcesets to the com.android.library plugin:
android {
compileSdk = 31
defaultConfig {
minSdk = 23
targetSdk = 30
consumerProguardFiles("proguard-rules.pro")
}
sourceSets.all {
java.srcDirs(file("src/android${name.capitalize()}/kotlin"))
res.srcDirs(file("src/android${name.capitalize()}/res"))
resources.srcDirs(file("src/android${name.capitalize()}/resources"))
manifest.srcFile(file("src/android${name.capitalize()}/AndroidManifest.xml"))
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
I don't know how to directly translate this into Groovy, but following the Android documentation, one can put something like this:
android {
compileSdk 31
defaultConfig {
minSdk 23
targetSdk 30
}
sourceSets {
main {
java.srcDirs = ['src/androidMain/kotlin']
manifest.srcFile 'src/androidMain/AndroidManifest.xml'
}
test {
java.srcDirs = ['src/androidTest/kotlin']
}
androidTest {
setRoot 'src/androidTest/kotlin'
}
}
}
Unfortunately this doesn't solve the problem. If nobody can show me workable Gradle scripts that don't create hideous and broken source file views in Android Studio, I will submit this as a bug to JetBrains.
IntellIJ is the recommended IDE to use when it comes to Multiplatform development.
Android Studio is for more Android Specific things, I don't think Android project view is something JetBrains wants to support, maybe there will be a Kotlin Multiplatform Project View at some point, but not at the moment.
(If you open a Spring, NodeJS, iOS or any other type of project the Android Project View will similarly seem broken)
I tried many tutorials and blogs for Setting up OpenCV Android Library on Android Studio
some of them are here
A Beginner’s Guide to Setting up OpenCV Android Library on Android Studio
Add OpenCV library into Android Studio
OpenCV in Android Studio
but i am unable to configure it according to above solutions
at start when i try to import module from /OpenCV-android-sdk/sdk/java android studio not showing module name edit box and hence i have to add "java" as a OpenCV module name
OK after importing module with the name of java we have to add dependencies but in add module dependencies not showing any module name java or anything
Guys anyone know how can i resolve this issue or any proper steps for OpenCV configuration in Android studio
I am using
Android Studio -4.0
opencv-4.3.0-android-sdk
First Screenshot: Android Studio may have removed that option in new version.
Second Screenshot: You can solve issue by editing build.gradle of Opencv as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
//applicationId "org.opencv"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Change apply plugin: 'com.android.application' to apply plugin: 'com.android.library'
and comment out the following line :
applicationId "org.opencv"
I've updated Android Studio to the latest canary build and now I can't run my app.
Every time when I try to build the project I get the following error:
Error:F:\...\**app_name**\app\build\intermediates\instant-run-support\debug\slice_0\AndroidManifest.xml:2 attribute 'android:versionCode' not found
I tried to manually open the file and the attribute is clearly there:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="****"
android:versionCode="1"
android:versionName="1.0"
split="lib_slice_0_apk">
</manifest>
I've tried to clean the project, invalidate cache, restart android studio but nothing helped.
This is my build.gradle (app) file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "****"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}
This issue is strictly related to Instant Run. Workaround: disable it inside File -> Settings/Preferences. This will at least allow you to run your app in the Canary version of AS.
This bug is solved since Android Studio 3.0 Canary 6, just update android studio and all SDK components and restart Android Studio.
Tested on:
Build #AI-171.4163606, built on July 7, 2017
JRE: 1.8.0_152-release-884-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Simply invalidating the caches did the job for me.
File > Invalidate Caches & Restart
No need to disable Instant Run or manually delete any build folders.
What worked for me is a combination of what robin and SamboyCoding said.
Clean Project from build menu
Rebuild Project from build menu
Then I could launch the app for testing without problems.
What worked for me was going into my project folder, and deleting the "build" folder, to force gradle to recompile everything. I also deleted the "gradle" folder, but had to recreate it manually because AS didn't, but I don't think it was this that fixed it.
I had the same. I tried either rebuild the project or change build gradle a bit(e.g change a versionName) and sync, then mostly the issue is temporarily gone.
The fastest workaround that works for me in Android Studio 3.0 Canary 2 is to add the versionCode and versionName attributes, and when the error occurs, I just change it to any other value (e.g. 1.0 to 1.1 and back). Then the app starts fine.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.XXX"
android:versionCode="1"
android:versionName="1.0">
As for 6/9/2017 Android Studio 3.0 Canary 3 the bug still exists. After trying all mentioned ways to fix this, the one that works is to:
Clean Project
Build Project
Disable/Re-enable Instant Run feature
or
Reload Android Studio.
In case of the error - suggesting to send report to Google via Help > Report Instant Run Issue.., also create a bug report in Groups. Don't forget to link this StackOverlow page - may be this way Google will fix this annoying bug fast.
I got the same problem. So I tried the stable version 2.3.1 of android studio. Then there come a question if I want to use the Android studios SDK, I select this.
Try to run the app, a Gradle error come up, which request minimum Android Studio 3.0.
I start Android Studio 3.0 C2 again, the question regarding the SDK come up again, but then the app compiles and the versionCode error was gone.
Clean and rebuild the project
and restart android studio.
It will work.
After cleaning and rebulding I disabled instant run and re-enabled it and the error is gone.
Update Android studio to Canary 3. They solved the problem
Every time I get this following error:
Error:D:\StudioProjects\yoda\app\build\intermediates\instant-run-support\debug\slice_0\AndroidManifest.xml:2 attribute 'android:versionCode' not found
I'd like to delete D:\StudioProjects\yoda\app\build folder, then select Build\Rebuild Project, and everything will become all right.
For me it was enough to delete .gradle folder in the root folder of the project
open the manifest file & close it.
if still not working: rebuild, open manifest file & close it, -> RUN
Recently, I've updated my android studio from 1.3 to 2.1. After that, when I trying to create a signed apk from "Generate Signed APK" in build menu. Android studio seems to works fine and prompting for successful generating release file, but always there is not such apk file in selected output folder. Also, open directory from successful pop up message does not work.
I try creating new keystore for signing and reinstalling android studio as suggested in some posts, but there is no change on issue..
This is build.gradle file I am using:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.vcc4.homeui"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile files('libs/gson-2.6.2.jar')
compile 'com.android.support:design:23.4.0'
}
I encountered the same problem. And I found out that the generated apk was moved from the "app" folder to the "app/build/outputs/apk/" folder.
I do not know if it's a bug or a feature but it probably has something to do with "Automatically Sign Your APK", as this article https://developer.android.com/studio/publish/app-signing.html#release-mode describes the folder mentioned above.
I ran into the same issue today. I restarted Android Studio and that could have solved the issue -- in the meantime, I had issues with ProGuard etc. that started failing my build, so maybe some Gradle sync, project rebuild etc. also came in handy
But I have a sneaking suspicion this is to do with restarting maybe AS or even your machine. I ran into this same issue last time I was trying to build a signed APK and everytime this seems to take up a few of my hours....I need to figure this out too
it seems that the apk generated will be in
{project-folder}/app/release/app-release.apk
I've implemented the new experimental build tools (gradle-experimental:0.2.1) for an app with many modules, but the current api is pretty awful and incompatible with certain libraries.
I'm curious if it's possible to pull all ndk code into a module and only process the ndk module with the experimental build tool and use the official build tools for the rest of the app. It'd be great to segregate all the experimental headaches into a small module.
I've tried a few things, but always ended up with gradle sync errors. Couldn't find anything online regarding whether this was feasible.
Part of my problem was an issue in the upgrade to AS 2.0. After fixing that issue I was able to do a quick test with the Hello World template project. I added a module and modified it to use the experimental plugin.
build.gradle (ndk module)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.4.0"
}
}
dependencies {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 11
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1"
}
}
}
Summary Update
I managed to get it working with ndk in a much more complicated project.
Here are the four primary requisites to get it working:
plugin gradle-experimental:0.4.0+ in your ndk module build.gradle (also convert to the new DSL)
plugin gradle:1.5.0 in your project build.gradle
Gradle 2.8 (gradle:1.5.0 plugin requires it)
Remove all jni from your main project (moved to module) since it's deprecated in 1.3.0+.
Without the combination of those versions of the gradle plugins I had lots of errors. Bit of a headache working out the kinks, but now I've segregated my ndk headaches to a simple module and I can integrate things like crashlytics that don't play well with gradle-experimental.