Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:10:45+00:00 2026-06-18T06:10:45+00:00

I am developing a generic Android game engine that will be used in many

  • 0

I am developing a generic Android game engine that will be used in many of my Android apps as the base system. The problem is that in all of my Java files I currently have to hardcode the package name like this:

package com.example.mygameengine;

But because I want to use the code of my generic game engine in many different apps, I need to find a way to specify the package name for the Java files at compile time because I do not want to keep several copies of my Java sources just because of differences in the package name. I want to have one central source tree and the package name should be dynamically changeable depending on the app I’m about to compile.

So is there a way to do something like this:

package $(PACKAGE_NAME)

In the Java sources where $(PACKAGE_NAME) is to be substituted with the real package name at compile time? Maybe javac has an option that allows me to specify a package name for the file it is passed instead of taking it from the file itself? Note that I’m not using Eclipse but barebones command line tools like ant and make.

EDIT: I do not understand why this is tagged as a duplicate. I’ve asked a fundamental question about whether the “package” directive in the Java language requires a hard-coded string argument in the source code or whether it is also possible to set this package name at compile time using a compiler directive. That’s quite a different question than the one that has been linked here as the presumedly “original” question which is much more closely tied to the Android build system. My question is about the fundamentals of the Java language, not about the Android build system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:10:46+00:00Added an answer on June 18, 2026 at 6:10 am

    You can’t. And that’s not the proper approach to code reuse.

    Simply package your commonly used code in a jar and include that jar in every project you want (in Android you do that by adding the class to the classpath, and then marking it as exported in the “Order & Export” tab)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a generic logging object which will be used within all of
I'm developing a generic app on PHP that is dynamically customized for many clients.
develop android apps that should support iphone,ipad,android.is there any way for developing this kind
I have a C program that I'm developing using Ubuntu 11.10 (Linux version 3.0.0-12-generic-pae
I'm developing an application that uses Navigation. The problem is that if the device
I'm developing a web app that emulates a generic file browser for the desktop,
I'm developing a simple cache functionality with EhCache. There is a generic base class
While developing a data access solution that utilizes generic repository and unit of work
I was trying to save time by developing a generic weak event listener that
I am developing a PhoneGap application for Android (will work on iOS too). The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.