Import some android classes in a java project (eclipse) - java

I need to have access to some android classes in a non-android project (just java project) in Eclipse.
What I actually need to do:
Class c = Class.forName("android.widget.Button");
Obviously I get a java.lang.ClassNotFoundException: android.widget.Button
Can I do what I want to do?

do not ad Android Classpath Container in eclipse , instead add individual android.jar..its recommended to add the highest android version and than create a local.properties file to store the location for your build script.

Related

Can i change signed android project package name?

I have an android project and the package is signed. When I want to change the package name, I get a "runtime exception" error. Is there any way to get rid of this signature?
If you are using Android Studio then use Refactoring instead of simply renaming Package Name. Right click on Package>Refactor>Rename.
Still better option is to create a new Project with your required Package Name and Copy all Java Classes and Resources to New Project.

How To Upload Android Library For Private Use Only?

I have an Android app but require to create two Different copies of it with different package names. The reason for wanting two package names is that I want to upload them to two different Stores which requires the developer to provide a different package name.
To simplify the update process and fixing the issues I thought of dividing my code to different libraries.
I have now created an android library and now want to upload it so that I can simply use the library in my projects by simply adding the line compile com.adc.aaa...
But I do not want those library to be accessible to other developers either directly of maybe through google Search. Is it possible to achieve this?
These are few links which I have visited regarding this matter
1) https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
2) https://mayojava.github.io/android/library/creating-and-distributing-your-own-android-library/
Can anyone please help.
Suposing your module in android studio is called "library" you can simply add the module to your app project locally without the need to upload it to bitray.
You can add a local module as a depedency to your project using AS or manually:
1) Using AS:
Go to File -> Project structure. Click on the app module and then depedencies, click on the plus sign and then choose 3 - Module Dependency. If you library is in the same folder as your app it'll show up there. Just select it and it will be added as a depedency like the other compile dependencies.
2) Manually
In your settings.gradle file add:
include ':app', ':library'
In your app leve build.gradle:
implementation project(':library')
If you library module is somewhere else you can inport it to your project using:
File -> New-> Import Module

AIDL Service and Android Open Source

I've created an AIDL service called IHelloService and I am trying to call it from IOBridge under the libcore module.
Currently my code looks like this
// import
import android.os.IHelloService;
import android.os.ServiceManager;
....
IHelloService helloService = IHelloService.Stub.asInterface(ServiceManager.getService("hello"));
int val = helloService.getVal();
I run into errors when doing a standard build.
The errors include package android.os does not exist and cannot find symbol ServiceManager and IHelloService
I've already declared package android.os in the HelloService aidl file, so I don't think that's the issue.
Any help would be appreciated.
Sang,
Your issue is actually one I have been working through. What you need to do is build a new SDK for use with that specific service so that Android Studio (I am assuming that is what you are using) can recognize it as being available in your version of the ROM.
Here is what you should do: (found at https://android.googlesource.com/platform/sdk/+/master/docs/howto_build_SDK.txt)
Go to your Android build area and run . build/envsetup.sh
Run the command "make update-api" in your build area. This will update the files with the changes or additions you have made to the api.
Run "lunch sdk-eng" to set up the build for the sdk.
To make the SDK, run "make sdk". This could take some time (20m - 2hr), but will end with the line "Package SDK: out/host/darwin-x86/sdk/android-sdk_eng..zip"
Now that the SDK is made, you will need to point Android Studio to the new SDK. TO do this:
RIght click on your app, and select "Open Module Settings".
Choose "SDK" from the menu on the Left.
Select your new SDK path.
There might be other ways to do this, but that is the process I am working with currently.

BaseGame Util cannot be resolved to a type

my project requires BaseGameUtil library
I have BaseGameUtil library downloaded form here
But when i import it in my android project it doesnt show baseGameUtil instead it shows main as added in my eclipse project and even when i add that main library i still get the same error.
Can anyone help me.
I think you may be using the version of BaseGameUtils in here:
...\android-samples-master\BasicSamples\libraries
But you are using Eclipse so you need to use the one in the following location:
...\android-samples-master\eclipse_compat\libraries
You may then also encounter an error with the GameHelper.java class in the BaseGameUtils folders. Use the code available here instead: https://gist.github.com/EmmanuelVinas/ef09a35bcc805ba6deb3
BaseGameActivity cannot be resolved to a type
public Class FisrstActivity extends BaseGameActivity{
In your project, right click > properties > Android > in Library section check if your library is correct and donĀ“t show any red cross.
Check the same for your BaseGameUtils library, probably the reference to google_play_services is incorrect.
you problem must be similar to : android - import - with developers google com games
Basegameutils from github includes all source .java files in java folder. When implementing in eclipse, move all these folders from 'java' to 'src'. Eclipse compiles them to produce .class files which fixes this problem.

Aniqroid library compilation

I want to change source code of aniqroid library https://code.google.com/p/aniqroid/
I create java application, add android library to "Java Build Path" and after that "Export".
Then add jar to my android project.
Problem is that when I start my application it crashes with ClassNotFoundException of "com.sileria.android.Application" that is used in the manifest.
If I just add source code to my application, then it works fine.
I suppose that I just have lack of knowledge about building. What am I doing wrong?
I appreciate any help!
UPD:
LOGCAT:
E/AndroidRuntime(9646): java.lang.RuntimeException: Unable to instantiate application com.sileria.android.Application: java.lang.ClassNotFoundException: com.sileria.android.Application in loader dalvik.system.PathClassLoader[/data/app/com.myapp.apk]
E/AndroidRuntime(9646): Caused by: java.lang.ClassNotFoundException: com.sileria.android.Application in loader dalvik.system.PathClassLoader[/data/app/com.myapp-1.apk]
Manifest:
<application
...
android:name="com.sileria.android.Application"
...
</application>
Solved by creating library project, but it is still interesting how to make jar.
Hmm okay I see after viewing the jar archive of library what the problem might be..
I take it you want to customize to use in own app rather than change library code
You will the Application class in the library aniqroid and the Application class mention in the android manifest will be the one in your main project with your app package naming scheme..
When you first type YourApp extends Application
the IDE will give you two choices, you want the second choice which will be your application class from the library you are attempting to use.
The problem was that I have built android application using jdk 1.6, but aniqroid library using 1.7. Changing to 1.6 solved this issue.

Categories