Jtransforms use in Android studio 2.3.2 - android

I am trying to use jtransforms in my project. I am new to android studio. I added the jatransoforms-with-dependencies.jar file as a new module.
Some other posts suggested to add jtransforms jar to the libs folder but there are many libs folders when I did a search and none of them show in the left hand side of the android studio dialog box (which shows the programs).
Now they also asked to do this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
The above two steps I could not do so I added the jar as a module from right clicking on the dialog box on the left side which shows project names. Now I am unable to delete the module (also please tell me how to remove this).
So lastly when I did this
import org.jtransforms.fft.DoubleFFT_1D;
it says "cannot resolve symbol DoubleFFT_1D".
There are many posts online to add a .jar file but and are varied (depend upon editor / studio version etc). Please tell me how do I add (and remove) the jar file to my project, use jtransforms FFT function.( i read other posts but were not useful).

Related

Linking an Android library that is on local machine

I have a set of utils and custom widgets that I want to pull out of my project as an Android library so that I can use them in other projects (and possibly share in the future). I created a new Android Studio project and changed the build.gradle file so that 'com.android.application' was 'com.android.library' and deleted the applicationId. It all compiles fine and I have a .aar file created.
I now want to use this new library as a module in my original project. When I do an Import Project, all the files from the library project are copied into my original project. But I don't want that because if I change the imported library code, it isn't reflected in the library project or vice versa.
I also tried adding this to settings.gradle:
include ':myutils'
project(':myutils').projectDir = new File(settingsDir, '../../../../Development/MyUtils/')
and in the original project app build.gradle:
dependencies {
implementation project(':myutils')
...
But I get this error:
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :myutils.
Show Details
Affected Modules: app
How can I link the library to my project without importing it? I would prefer not to go through an external maven repo yet. I'm happy to (and would expect to) recompile my library whenever there is a change there and then rebuild my original project.
Thank you in advance.
I think I just had the same problem - I wanted to put the library .aar file somewhere on my local drive and then use it in a new app as a dependency. I didn't want to have to go through a repo or to include it in the libs folder in the new app. Hopefully that is what the OP asked and the following might be of help to others.
Searching on SO (Aug 2021), majority of answers seemed much more involved than what Android Studio offers (tested on version 4.2). That is, an .aar file that lives outside the app project can now be added as an implementation file in the gradle dependencies. So, it doesn't have to go through a repo, and it doesn't have to be included in the libs folder in the project.
The current documentation (Aug 2021) gives a fairly straightforward answer how to do it:
https://developer.android.com/studio/projects/android-library#psd-add-aar-jar-dependency
In short, if you have put your .aar file somewhere on your local drive, this is how to add it as an implementation file in another app project:
In Android Studio, in your new app project, go to: File > Project Structure > Dependencies.
In: Modules > app > Declared Dependencies, click '+' and select 'Jar Dependency'. (Even though you are trying to use an .aar file, you still select 'Jar Dependency').
In the 'Add Jar/Aar Dependency' popup dialog:
in step 1 enter the path to your .aar file on your local drive, and
in step 2 select 'implementation'.
If everything worked out, your build.gradle(Module) should have a line in the dependencies that looks like:
dependencies {
implementation files('../../../MyFolder/MyLibraryFile.aar')
A few notes:
You can actually just add the dependency manually, by typing it into the build.gradle(Module) dependencies, so you don't actually have to go through the Android Studio dialog outlined above.
you can either use a relative path (as the example above), or an absolute path.
the Android Studio dialog is somewhat limited in that you cannot just browse to your file (in point 3, step 1), but you have to actually enter the path manually.
Probably the most important: Whenever you make a change in the library and assemble a new .aar file, then remember to do the following in your app project that uses the .aar file as a dependency: Clean Project, then Sync Project with Gradle Files, and only then run the app, so that the changes in the library could take effect in your app.
I have been using Phgr's above technique for four years. I have three comments -
First, I don't clean the app project each time I change the library - I just do a Sync Project before building and testing the app.
Second, I changed the File-Settings-Keymap-Main Menu-File-Sync to Alt-S for easy of syncing - I hate wasting time using the mouse for selecting the Sync icon.
Third, I have an implementation line in the app's build module file for each app variant such as the following -
debugImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-debug.aar')
releaseImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-release.aar')
All of this is working fine with Android Studio 4.2.2 and sdk version 30.
Hope this helps others with this problem

error :the package com.badlogic.gdx does not exist

I receive the "error :the package com.badlogic.gdx does not exist" when you try to start the project.
In my project there is a libGDX. Classes see it and objects from this libGDX are used. But when trying to compile an application, this error occurs.
At the same time, there are no errors in the classes on which this error is made.
"Sync Project with Gradle Files" and "Invalidate caches/restart" did not help.
Someone came across similar? How to fix this?
enter image description here
Go to libs folder, right-click on libraries you want then select: Add as library
The reason is, you should add the external libraries on Build.Gradle if the online source from maven-jcenter or etc is not available and you have to add them manually.
After doing this, try rebuild the project then you're good to go.
Or in code: (in not added cases by IDE)
implementation fileTree(dir: 'libs', include: ['*.jar'])
Replace the name instead of * in above code.
How to add a jar in External Libraries in android studio
And: How to add a jar in External Libraries in android studio

No resource found that matches the given name 'Theme.AppCompat.Light'

I am having problems setting up my eclipse program with Android for my first project. After installing eclipse together with the android developer tools, I tried to create a new 'Android Project' with a minimum sdk of Android 2.2, a target sdk of Android 6.0 and a sdk compiler of Android 7.1.1.
After clicking run, Eclipse displayed an error, which indicated that there was issues with my empty activity:
Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'
I have done my research for this problem and most of the solutions suggested importing an Android Project called "AppCompat-v7". However, upon selecting the file, there were no projects found that could be imported. This is what I see:
Import project window:
I have spent numerous hours trying to fix this issue. I have ensured that both my eclipse program and all android files are under the same hard disk, I have tried adding the file to the build path etc. but the same problem persists.
Anyone out there who can help me with this issue please? I would greatly appreciate it :) If you need more details regarding what I have done so far, feel free to contact me!
Someone commented below suggesting that I import the "AppCompat-v7" folder to the package explorer and then go to Project->Properties to add the appcompat library folder. I managed to add the folder to my package explorer but I am not able to add the library to the project, as no library options show up. This is even so after checking the "IsLibrary" box.
AppCompat-v7 should be added to your module Gradle file.
It goes in the dependencies section.
For example:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
}
if you have Appcompat v7 in your extras folder follow this link but if you don't have it:
To download the Support Library through the SDK Manager:
Start the Android SDK Manager.
In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
Select the Android Support
Repository item. Click the Install packages... button.
After downloading, the tool installs the Support Library files to your existing Android SDK directory. The library files are located in the following subdirectory of your SDK: <sdk>/extras/android/m2repository/com/android/support/ directory.
Update: Import it like this picture
you are now have your library in your project Explorer like this
the rest is adding library project

Auto link source code downloaded by Gradle

Sorry if this question is duplicated but I have searched for a while and couldn't find the answer.
I use Android Studio and Gradle to develop my app, gralde will auto download source code from maven but then inside Android Studio it's said that "Sources Not Found" and I have to drag drop or select the source files directly. This is very troublesome. Is there anyway that AS auto link the sources downloaded with the class, and when I ctrl + click on the class it will open the source file directly?
Edit: Some libraries like ButterKnife I can view source code directly, but others like MaterialEditext I have to select the source file manually.
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.rengwuxian.materialedittext:library:2.0.3'
ButterKnife can be found in External Library while MaterialEditext isn't. I don't know why.
Not every module you want can be selected automatically. Only those you can find in dependencies could be imported by Gradle. Take a look here:right-click at your project --->Open Module Settings--->Modules--->Dependencies--->Plus--->Library Dependency, and then you can select one Library Dependency. And then it will be added into your project by Gradle. Most importantly, What You Can See Is What You Can Get. If you can't see the module you want, maybe you need to download it somewhere else.

Android Studio: how to setup generated Cloud Endpoints sources?

I built a Cloud Endpoints API using AppEngine/Python (not with the Java wizard from Android Studio), then I generated the libs and sources, copied the libs stated in the tutorial to libs/ and extracted the sources.jar file to src/
adding to build.gradle: compile fileTree(dir: 'libs', include: '*.jar')
the problem I'm now facing is:
08-04 19:40:53.756 2052-2052/com.dgt.ddst E/dalvikvm: Could not find class 'com.google.api.services.dsApi.DsApi$Builder', referenced from method com.dgt.ds.MainActivity$1.doInBackground
08-04 19:40:53.756 2052-2052/com.dgt.ds E/dalvikvm: Could not find class 'com.google.api.services.dsApi.model.ServicesDResponse', referenced from method com.dgt.ds.MainActivity$1.onPostExecute
I searched for solutions and all I could find are things related to Eclipse.
how do I fix this in the Android Studio/Gradle environment ?
This is how I did it, maybe it is not the best way but I couldn't find a better one:
First generate your client library for gradle:
google_appengine/endpointscfg.py get_client_lib java -bs gradle your_module.YourServiceClass
Uncompress the generated zip file, this will create a folder call your_module
In Android Studio load the Android app you want to work with your endpoints module
Go to File -> Project Structure. Add a new module selecting "Import existing project". Point the source folder to your_module folder and then press finish.
Android Studio will go back to the Project Structure window, select your Android app module and go to the dependencies tab. Add a new "Module dependency" and select your_module.
Re-sync gradle and rebuild your project and that's all!

Categories

Resources