Which is the right place to specify android's library project version code/name? Whats the current state on a library's Android Manifest? When you bundle a library jar, can AndroidManifest be ignored while bundling jar and still delivering a usable/unbroken jar?
My question is related with this
You set version code/ name of a project in its AndroidManifest.xml. But if it's a library project, all information in the manifest will be ignored after integrating into the host project.
There is an issue.
BuildConfig.VERSION_NAME
BuildConfig.VERSION_CODE
Just make sure that you import the BuildConfig for your library (as literally every android library/app has it's own BuildConfig on it's package path). The Android Studio's Gradle Build system indicates that this is always generated as of version 0.7.0 (see changelog). This persists as a generated class into the hosting app/library.
Related
I'm maintaining a legacy app built with a legacy ant built system and have made some changes to it to support the Android M permission changes.
I temporarily created an Android Studio project while evolving the changes and imported all the source files into to. A change I needed to do was to add this dependency to the build.gradle
dependencies {
compile "com.android.support:support-v4:23.0.0"
}
Now the source file changes are complete the project now needs to be built using the old legacy ant system. However I don't how to to back-port the gradle dependency.
I tried adding it to the manifest like this:
<uses-library android:name="com.android.support:support-v4:23.0.0" />
But when the apk is attempted to be installed there is an error:
Failure [INSTALL_FAILED_MISSING_SHARED_LIBRARY]
How do I add the dependency if not using gradle?
Rewriting the build system to be up to date and using gradle is not an option at this stage.
However I don't how to to back-port the gradle dependency.
For support-v4: "Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory." (from the Eclipse setup instructions)
<uses-library android:name="com.android.support:support-v4:23.0.0" />
<uses-library> is for firmware libraries (e.g., the old Maps V1 stuff) and has nothing to do with Gradle-style dependencies.
Rewriting the build system to be up to date and using gradle is not an option at this stage.
You have ~77 days, so you had best get working on it. After the end of 2015, do not expect any support for the legacy build system, including standalone Android Support JARs. If you get support after the end of the year, consider it a gift from the heavens.
I'm trying to compile Java module in Android Studio.
I'm also referencing android.jar in the module. So, yes, module is supposed to be Java, but uses android.jar as compilation reference.
The version SDK for this android.jar is irrelevant (I think, but it is 19 something).
(You might ask why if I need android.jar don't I use Android module instead of Java?, well it is intermediary step to restructure our Android project).
The problem I'm facing:
error: cannot find symbol variable SDK_INT
apply plugin: 'java'
dependencies {
compile project(':ATTLogger')
compile project(':BandwidthController')
compile project(':iwpstack')
compile files('libs/android.jar')
}
You see – IT doesn't want to recognize some… code clearly present in the android.jar.
And yes it sees import android.os.Build; and doesn't complain about it.
Here is my bukd.gradle:
Please help if you happened to solve this nuisance I've wasted half a day on.
Thanks!
If it is a Java only code (without any calls to Android API) then you can make it a JAR without adding a dependency to android.jar. Otherwise, if you have calls to Android API, you should make it AAR module.
From http://developer.android.com/sdk/installing/studio-build.html#projectModules :
Java library modules contain reusable code. The build system generates a JAR package for Java library modules.
Android library modules contain reusable Android-specific code and resources. The build system generates an AAR (Android ARchive) package for library modules.
Android application modules contain application code and may depend on library modules, although many Android apps consists of only one application module. The build system generates an APK package for application modules.
So to fix your issue, you should skip this "intermediary step" and make it an Android module right away.
I have created 2 project 1 is Lib and 2nd in Test.
From test app I pass context to Lib project.
As I have context in Lib, i used below code inside Lib
String version = this.mContext.getPackageManager().getPackageInfo(this.mContext.getPackageName(), 0).versionName;
Log.e("versionName", version);
But this gives me version name of test app and not lib.
How should i get application version name and code for Lib?
Reference link:
How to get version information of an included library?
BuildConfig.VERSION_NAME
Just make sure that you import the BuildConfig for your library (as literally every android library/app has it's own BuildConfig on it's package path). The Android Studio's Gradle Build system indicates that this is always generated as of version 0.7.0 (see changelog).
I have an Android library project. I include the version of the library in its manifest. I use this version internally, so right now I also have the version stored as a static constant. Is there any way to read the version of the library project from the manifest so I can remove this redundancy? From my searching, I'm guessing that the answer is no, since library project manifests are in essence discarded during the build process.
I have modularised some simple classes into their own project for reuse elsewhere. These classes typically contain only fields and accessor methods (i.e. nothing Android specific).
They are later packaged up using ant's jar task and stored in a Maven repository.
In an Android project, I've stored said jar file into a libs directory and added to the build path. On running the emulator however, I get a "class not found" exception relating to my package. Other third party libraries (such as GSon) are being picked up fine.
Are there any specific steps required to make a jar file compatible with Android? (This reply seems to suggest otherwise). How can I debug this further?
No as long as you do not need e.g. classes from javax.* that are not in Android. If I were you I would consider looking at using the Android Maven Plugin for your build though. Check out the morseflash example from the official samples collection. It showcases exactly your scenario.
You only need an Android library project if your going to be reusing Android components and resources. In your case, I believe you added the project to the build path, but I'm sure your not exporting it as part of the dependent project.
So open the project properties, open up the Java Build Path options and make sure that you have your JAR selected as an exported dependency in the Order and Export tab.
UPDATE
This is what your entry should read:
<classpathentry exported="true" kind="lib" path="libs/tlvince-dao-0.1.0.jar"/>
I've also forked an updated version of your gist.
This issue was a result of compiling the jar to Java 7. Android does not support Java 7 (yet).
Compiling to Java 6 bytecode by setting target="1.6" in ant's javac task solved the issue.