Freshly imported Android Studio project errors with zxing module - android

I have been using zxing module as an android library for some time without problems. I have imported my Eclipse project into Android Studio (which I use for everything else!) and the zxing library is added as a module.
In one of my classes in the main module I reference the com.google.zxing.android.client.Intents class which is in the zxing module. I can write code in Android studio and these references have the correct imports selected.
When I run a gradlew clean build I am getting messages saying 'cannot find symbol class Intents'.
In settings.gradle I have includes for both my main module and the zxing module.
In the build.gradle of my main module I have 'compile project(':zxing'). These were both added during the import from Eclipse. I can also see that the zxing module is being built as part of the gradlew clean build.
I have tried deleting the zxing module and references then trying to add it manually. I have compared the way that this module is implemented to another project with a similar module that works. All looks fine.
Is anyone able to make a suggestion?
Edit:
settings.gradle file
include ':app'
include ':captureActivity'
build.gradle of main module
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.wigglyamps.littlegreenbutton"
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':captureActivity')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
Java class file in main module
public class test {
public void hello () {
String i = Intents.Scan.ACTION;
}
}

I don't really know the zxing framework, but have you tried to use the maven artifact instead of referencing a module?
If you want to use the artifact add this to the dependencies of the project/module that uses zxing: compile 'com.google.zxing:core:3.1.0'
Edit: You said you imported the project from eclipse; I'm in the middle of transitioning to gradle and the import function hardly produces anything useful if the eclipse project contained references to library projects (not jar's). I rebuild my projects from scratch by creating a new app(with modules) in Android Studio and copy/paste code and resources into the new app's directories

Related

some strange android error

https://github.com/mustafaakin/image-matcher
I imported this project using AndroidStudio's "Import Eclipse Studio Project". Edited .properties 'OpenCV - x.x.x' to 'opencv'. This is the error:
/home/uttaran/Downloads/h1/h/src/main/res/layout/main_layout.xml
Error:(62) No resource identifier found for attribute 'camera_id' in package 'in.mustafaak.imagematcher'
Error:(62) No resource identifier found for attribute 'show_fps' in package 'in.mustafaak.imagematcher'
Error:Execution failed for task ':h:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/uttaran/Android/Sdk/build-tools/23.0.3/aapt'' finished with non-zero exit value 1
Information:BUILD FAILED
As Daniel K already stated correctly:
To important an Android Application/Library in Android Studio, the project you want to import needs a build.gradle or pom.xml file in the root of the project so that the build system (Gradle/Maven) that comes with Android Studio can resolve dependencies etc. during the project import...
The Github project you refering too is this?
https://github.com/mustafaakin/image-matcher
Apparently it got written with the Eclipse IDE...and pushed to Github without any build file...
You can import it anyway, by manually creating a build.gradle file in the project root and then try to import the application again.
A possible working build.gradle file (depends on your Android Studio's Gradle plugin Version etc. I just assume now you copied your build.gradle file from a working project of yours) would be:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
}
If you did this, it probably will not find the OpenCV library dependency (red lines under OpenCV classes/methods and in imports) and you have to go in Android Studio to:
File | Project Structure | image-matcher-master | Dependencies | +
And there you add your OpenCV library as "File dependency"...if it is a JAR...otherwise if opencv in your Download folder is the source...you load this in Android Studio as well and choose "Module dependency".
If this doesn't work...this could be helpful as well:
http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html
UPDATE:
main_layout.xml contains things like:
<org.opencv.android.NativeCameraView
android:id="#+id/tutorial1_activity_native_surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="cameraclick"
android:visibility="gone"
opencv:camera_id="any"
android:layout_weight="1"
opencv:show_fps="true" />
So your OpenCV library comes with resources and views that can't be found, so you still have some problem with your src structure in your project.
This answer might be related:
Android Studio can't find opencv modules, but compiles ok
If nothing works I would recommend to import an OpenCV Android sample, check if it builds and compiles and then compare the src structure difference from your project to the sample project...
Open the Android native Camera using OpenCV

Duplicated assets in .jar file created by android studio

I have an android studio project, the project has an application module and a library module. The application module is simply a demo of the library module. The library module depends on a third party, for the sake of simplicity, let's call it external.jar.
Android studio could successfully build the library module, generate a library named classes.jar.
I noticed that android studio also copied assets from external.jar into classes.jar along with .class files. The problem emerged when I was trying to build an apk from the application module, because the application module depends on external.jar, android studio refused to assemble the final apk due to duplicated assets, and showed the following error message:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK assets/ap1.data
File1: /Users/skyrim/android/Demo/app/libs/classes.jar
File2: /Users/skyrim/android/Demo/app/libs/external.jar
I have to release the library module in binary form to third parties, they may also use classes.jar along with external.jar, so excluding unnecessary assets is a must.
The following is my library module's build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
}
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:23.2.0'
}
How can I prevent android studio from copying assets from external.jar into classes.jar ? Of course, I can simply unzip classes.jar and move unnecessary assets and re-zip it, but I prefer some less hackish solutions.
I'm new to android development and gradle build system, any suggestions are welcome.

Android how to create library (jar) containing Altbeacon library with Android studio and gradle

I'm a newbie in Android especially for libs.
I'm using Android Studio 1.2.2
I'm trying to create a jar library with no activity, resources, etc (only code) that use the AltBeacon library. When complete I whould like to include this jar in my APP that has to use beacons through my lib.
Well, using AltBeacon instructions, I'm able configure gradle to have a "normal" (with activity etc) APP using AltBeacon library. But I'm not able to create a jar library that contains the AltBeacon one.
I google a lot especially in SO, I found a lot of questions about "library inside library" but that doesn't worked for me.
I made this:
I created an empty project with Studio (blank activity)
Then I created a new module -> Java Library and called it libmebeaconmanager and Studio created a new Java class that I called MeBeaconManager
I modified the build.gradle of the library in this way:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2+'
}
This is the build.gradle of Module:app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "me.padovame.libbeacontest"
minSdkVersion 18
targetSdkVersion 22
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:22.2.0'
}
And this is the build.gradle of project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
At this point, in the MeBeaconManager class of the lib, I tried to import AltBeacon classes without success because I got an undefined symbol error for import lines like this:
import org.altbeacon.beacon.Beacon;
I also tried, without success, inserting in lib folder of libmebeaconmanager the downloaded android-beacon-library-2.3.aar
What am I doing wrong?
Thanks in advance.
EDIT:
I tried to include a jar (tried with Picasso) library in my libmebeaconmanager and it worked. So the problem seems to be with aar libs.
I'm going crazy...
EDIT 2:
I extracted classes.jar from the AltBeacon aar lib and used as other jar and it worked.
But I consider this as a workaround: I still do not understand how to manage directly aar files. So thanks to whom can help me.
Seems like there is a problem in inserting library to project structure
You can have a look at answer provided by user Sam Rad here:
How do I add a library project to Android Studio?

Why does Android Studio don't recognize .jar library imports?

I'm trying to use some .jar files as libraries in my Android Studio project.
I've been looking on how to do it, and the regular way is to copy the .jar file in the libs folder, and then add it as library. I know the libs folder must be inside "app" module in the "project" view. But that option to add as library doesn't appear. So my approach is to add it manually doing right click on "app" and:
Open Module Setings/app/Dependencies/ and there add .jar files as file dependency.
Then, I go to my .class but the import suggestions don't let me select these libraries as import.
I have tried another approach from the "android" view. Doing right click on "app" and selecting "new module", there I select Import .JAR or .AAR Package and then I do the same as before from Open Module Setings, but this time I add it as Module Dependency.
In booth ways, the gradle.build file is updated adding these dependencies, but when going to the activity to select the import, it doesn't give me the chance to select the import from these ones.
I have spent a full day trying to solve this, but I don't get my activity to recognize the imports from these files, so I would appreciate if someone could tell me what I'm doing wrong or what I'm missing to do.
Top-level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
app-level build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/values-v14'] } }
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':activation')
compile project(':mail')
}
My current project using gson-2-2.4.jar and YouTubeAndroidPlayerApi.jar and some others. To import those jar, I put it in my libs folder. After that, go to build.gradle and delete some characters in it, and rewrite (1). Finally, click "sync now" (2). I don't know why my sync button does not work when I add jar to libs, so I do that, and it work so well.
UPDATE
On Android 3.x.y we can use Sync Project with Gradle Files or Refresh all Gradle projects
Firstly, I import this JAR, AS can not recognize this JAR and I can not import.
And than I press right click in this JAR and choose "Add as Library". AS can recognize this JAR and solve the problem!!
With Respect to Android Studio 1.5.1:
You need to copy and paste the JAR file into:
APP_NAME/app/libs
Note that the libs folder will already exist. Once copied, change the project view from Android to Project files.
Open up the app/libs folder and right click the JAR file, then click Add As Library.
That should do it. I wasn't able successfully use the Add Module to import a JAR file.
After a chat with M D we arrived to the conclusion that my AS does not recognize the .jar files, so I have had to port the project back to eclipse, and it works fine there.

Import Facebook SDK on Android Studio 0.5.1

I've been searching around for a while now and tried every answer I could find with no success. I am starting to believe that the problem is in the android studio version.
However here is what I've done:
1 - I've downloaded the facebook sdk
2 - Copied the sdk into my libs folder so the project looks like
following:
MyProj
-app
--libs
---facebook
----build.gradle (2)
--build.gradle (1)
-settings.gradle
3 - I modified settings.gradle:
include ':libs:facebook', ':app'
4 - I modified build.gradle (1) to:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'me.dm7.barcodescanner:zxing:1.0'
compile 'com.koushikdutta.ion:ion:1.2.4'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.squareup.picasso:picasso:2.1.1'
compile project(':libs:facebook');
}
5 - Lastly edited build.gradle (2):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Now when syncing I get the annoying warning:
Gradle 'MyApp' project refresh failed:
Configuration with name 'default' not found
And I am not able to use the facebook library.
I guess I'm doing something wrong with the gradle files. Any ideas?
On Mac with Android Studio 0.5.8, this is what worked for me:
Click on the top level project and select project structure:
Click the + to add another module
Click on "Import Existing Project" and "Next"
Select the facebook directory from your SDK folder and click next
The facebook module should now be shown in addition to your existing module
Click on your project, select the Dependencies tab and click '+' to add a dependency.
Select "Module Dependency" as dependency type.
Select the Facebook module that we just added
Note that it shows up under dependencies (of your app)
And you're all set!
The directory structure of your project doesn't match the dependency specs you're using; it's not clear what's in your settings.gradle. That error you get with "Configuration name 'default' not found" is terribly unintuitive, but it's the message you get when Gradle is looking for a module in a certain directory and it's not finding it. If you have a dependency spec (and settings.gradle include) like :libs:facebook, it will look in MyProj/libs/facebook, not MyProj/app/libs/facebook where you've placed it.
I would recommend this structure:
MyProj
-app
--build.gradle (1)
-libs
--facebook
---build.gradle (2)
-settings.gradle
i.e. move the libs directory one level up so it's alongside app directory instead of underneath it.
Your settings.gradle file should be:
include ':app', ':libs:facebook'
(which is probably how you already have it set up) and a dependency on facebook should look like:
compile project(':libs:facebook')
(also like how you already have it set up)
Follow this step to add Facebook SDK to your Android project.
1) Open your fresh Android project
2) Go to File -> Project Structure (or) Alt+Ctrl+Shift+S
3) Go to module click + on second row of window then import module
4) After Facebook SDK imported click + on third row and select Module Dependency select Facebook SDK Apply and press ok
I made a Facebook Module version from scratch https://github.com/cesarferreira/Facebook-Module
If you want to use this module for your projects you should follow the next steps:
You should create a new 'libs' folder in your project root
You should copy this project into the 'libs' folder, you must manually copy the project, because if you copy it using the drag and drop action the project doesn't work because android studio throw an error
Add the next line into settings.gradle file: include ':libs:facebook'
You should rebuild the project
THAT'S IT!

Categories

Resources