I've just moved one of my Android projects over to Gradle, and as per recommendations inside the IDE and online I've moved all the configurations (min/max sdk, version name/code etc) into the build.gradle file.
Now a bug has been reported from a customer that where he could usually see the version name and code inside the product there is nothing.
After checking it out I've found out that the usual way of extracting those values has stopped working after I removed the android:versionCode="" and android:versionName="" tags from AndroidManifest.xml. I have verified that it works when these values are there.
Now I've been trying to search for a way of extracting these same values to use in code, but I have not found any reference to this behaviour else where (this not working like this).
The code I used to use to get the values was to simply extract them from the PackageManager as so
try {
PackageInfo pInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
return pInfo.versionName + " Build " + pInfo.versionCode;
} catch(PackageManager.NameNotFoundException e){
e.printStackTrace();
}
All hints, tips or solutions appreciated.
Use the BuildConfig class to fetch your version code which are defined in build.gradle file:
Log.e(TAG, BuildConfig.VERSION_NAME + " Build " + BuildConfig.VERSION_CODE);
Related
I've been searching around all over the internet to no avail. I am attempting to use Guava to get all the classes in a package of mine, but it is not behaving as intended. It always returns an empty set, making it impossible to do anything with the given results. Could there be a problem with System Variables, or some other road-block?
Here is some of my code.
String packageName = "me.travja.package";
ImmutableSet<ClassPath.ClassInfo> root = null;
try {
System.out.println(ClassPath.from(getClass().getClassLoader()));
root = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses();//.getTopLevelClassesRecursive(packageName);
} catch (IOException e) {
e.printStackTrace();
}
for (ClassPath.ClassInfo info : root) {
System.out.println(info.getPackageName() + " -- " + info.getSimpleName());
}
It never hits the last sout because it's empty, but the one that prints the classpath prints 'com.google.common.reflect.ClassPath#33571c14' which isn't super useful. But to my knowledge, shouldn't that resemble more of my application's directory?
Thank you for your help with this. It's been bugging me for too long.
EDIT: I did some digging around. It seems that it works as intended if my file path doesn't contain a Space. I read a little that this used to be a problem with Guava in older versions, but I even tried using Maven and shading the latest version of Guava. Is there any way to fix this, or do I just have to be cautious that my file path never has a space in it?
After doing some more digging, one of the other dependencies that I was using had shaded an older version of Guava and that is what my code was using. As a result, it was broken. I used a decompiler so I could manually shade the ClassPath class from a newer Guava into my own code, and imported that. Works flawlessly now.
I am having the following problem:
I have an Enum that was originally declared with 5 elements.
public enum GraphFormat {
DOT,
GML,
PUML,
JSON,
NEO4J,
TEXT {
#Override
public String getFileExtension() {
return ".txt";
}
};
Now I need to add an additional element to it (NEO4J). When I run my code or try to debug it I am getting an exception because the value can't be found in the enum.
I am using IntelliJ as my IDE, and have cleaned the cache, force a rebuild, etc.. and nothing happens. When I look at the .class file created on my target folder, it also has the new element.
Any ideas on what could be causing this issue ?
I found my problem and want to share here what was causing it. My code was actually for a Maven plug-in which I was pointing to another project of mine to run it as a goal. However the pom.xml of my target test project was pointing to the original version of the plug-in instead of the one I am working on, and that version of course is outdated and does not include the new value. Thank you.
I am trying to write an application from extracting entities from a text and want to use GATE jar files. For which I have installed the GATE tool and have imported jar files, but it is giving errors. I can't understand from where to download more jar files and how to run the first simple program with this.
Please make sure that you added gate.jar from YOUR_GATE_HOME/bin folder.
From your screenshot I can assume that you used an example provided by GitHub. This example looks good, except one part (from my point of view of course). I would suggest to replace output piece with the next more readable code:
String text = "Steve works for Apple Inc in California.";
Document gateDocument = Factory.newDocument(text);
corpus.add(gateDocument);
// tell the ANNIE application about the corpus and run it
annie.setCorpus(corpus);
annie.execute();
List<Annotation> personAnnotations = gateDocument.getAnnotations().get(ANNIEConstants.PERSON_ANNOTATION_TYPE).inDocumentOrder();
for (Annotation personAnnotation : personAnnotations) {
System.out.println("Entity Text: " + gate.Utils.stringFor(gateDocument, personAnnotation) + " Features: " + personAnnotation.getFeatures());
}
Similar things could be done for Location, Organisation and other Entity types defined in GATE. Also do not forget to release resources with Factory.deleteResource().
I thought this would be a very simple thing. So far however I'm unable to access the String for my gradle job's Java.Home, the official name:
For example, see: org.gradle.java.home
Apparently I can set this value with gradle.properties settings file. I've done that and the gradle output confirms this.
For all that, none of these print statements work...
print "org.gradle.java.home = $org.gradle.java.home"
print "org.gradle.java.home = "+ project.properties['org.gradle.java.home']
print "org.gradle.java.home = $gradle.java.home"
print "${project.property('org.gradle.java.home')}"
Looking at back at this question, I would have thought one of the options tried would yield a result.
How can I access system level properties?
Only two options may work:
print "org.gradle.java.home = "+ project.properties['org.gradle.java.home']
print "${project.property('org.gradle.java.home')}"
and the second will fail since there's no checking if such property exists. Gradle throws an exception on access to non-existing property.
The last two will not work because there's no property org and gradle objects has no java property - more explanation can be found here - you need to understand how string interpolation works with groovy.
And finally, these properties are used to pass arguments to gradle. So the following will work:
print "org.gradle.java.home = "+
project.properties['org.gradle.java.home']
run with:
gradle -Dorg.gradle.java.home=random_dir
With some trial-and-much-error, I have found that one may print the java.home property on Windows with Gradle 2.4; when ...
Use your gradle.properties file, e.g.
For example
compile.options.fork = true
org.gradle.daemon = true
org.gradle.java.home = b:/lang/java/jdk/v1.8u45
The same settings in GRADLE_OPTS had no effect. The print command used, is:
print "org.gradle.java.home = "+ "${project.property('org.gradle.java.home')}"
I believe the compile.options.fork is also required. It had no effect before when I was using GRADLE_OPTS. Although the Gradle message to use fork is quite clear on the matter.
see also:
- https://docs.gradle.org/2.4/userguide/gradle_daemon.html
i'm using the LibGdx framework to create a game and I'm using Eclipse 4.4 (Luna). Whilst i'm debugging my application this method is breaking.
#Override
public void run() {
setName("GLThread " + getId());
if (LOG_THREADS) {
Log.i("GLThread", "starting tid=" + getId());
}
try {
guardedRun();
} catch (InterruptedException e) {
// fall thru and exit normally
} finally {
sGLThreadManager.threadExiting(this);
}
}
inside the GLSurfaceView Android class, with the stack trace:
Thread [GLThread 232] (Suspended (exception NullPointerException))
GLSurfaceView$GLThread.run() line: 1243
I know what a NullPointerException is, I know somewhere is passing a null value, but what I would like to know is how can I find out where?
With these types of questions, I can only assume you'll need more code but I don't know where I should be looking, I'll post code from the Java classes on request if anyone has an idea of where I should be looking.
Note: I'm not using GLSurfaceView directly anywhere in my code, I'm assuming it's a library from Libgdx. Unless it's something i'm missing?
UPDATE: Found the issue in detail.
GLSurfaceView$GLThread.class [in android.opengl [in C:\Users\me\AppData\Local\Android\android-sdk\platforms\android-8\android.jar]] does not exist
Solution:
An AtlasRegion was being called from the renderer class without being assigned a value in the assets class hence the null Exception
What is a NullPointerException, and how do I fix it?
changing that to a field that is declared solved this problem for me on the code side.
For the solution to the backend issue:
GLSurfaceView$GLThread.class [in android.opengl [in C:\Users\me\AppData\Local\Android\android-sdk\platforms\android-8\android.jar]] does not exist
I downloaded source codes from Google, and assigned the source code inside the SDK folder, C:\Users\me\AppData\Local\Android\android-sdk\sources\, if you don't already have a source folder create one, put the sources in there and it should reload the class that was being handled. (in this case GLSurfaceView.class for API 2.2)
Another way In Eclipse 4.4 (Luna) or any other eclipse I do believe, go onto your project folder right click > properties > java build path and assign the source file for android.jar in your dependent libraries.